我有一个关于重定向的问题。我在URL中放置了一些参数,因此可以使用$ _GET将它们删除,然后将它们放入变量中。现在,当我填写错误的表格时,我会被重定向,但所有参数都丢失了,它们不再在变量中了。有没有一种方法可以使用相同的参数重定向到同一页面?
带有参数的url:http://本地主机:8888 / WD2 / Week6 / Project / flight_bestel.php?座位号= 5&价格= 99.00&目的地=西班牙&到达=%20巴塞罗那%20Airport
重定向后的网址:http:// localhost:8888 / WD2 / Week6 / Project / flight_bestel.php
谢谢
<?php
session_start();
include_once ("scripts/config.php");
include_once ("scripts/api.php");
$stoelNr = $_GET['stoelnr'];
$prijs = $_GET['prijs'];
$bestemming = $_GET['bestemming'];
$aankomst = $_GET['aankomst'];
if($_SERVER['REQUEST_METHOD'] === 'POST') {
}else{};
?>
<?php require_once( 'views/shared/_header.inc' ); ?>
<body>
<header>
<?php include( 'views/shared/_nav.inc' ); ?>
</header>
<main>
<div id="contents" class="container">
<section id="summary">
<form action= "<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-info" name="bestel">Bestel nu!</button>
</div>
</div>
</form>
</section>
</div>
</main>
<?php require_once( 'views/shared/_footer.inc' ); ?>
So your question becomes..."How do I rebuild the original URL as the action for my form"?
One way to do that is to grab the query string and use it to rebuild your forms "action".
Something like... Grab your original query string
$query_string = '?'.$_SERVER['QUERY_STRING'];
And append it to your forms action
<form action= "<?php echo $_SERVER['PHP_SELF'] .$query_string; ?>" method="post" class="form-horizontal">
That should get your going in regards to that bit of the puzzle you are working on.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句