我有一个关于重定向的问题。 我在我的URL中放了一些参数,所以我可以使用$ _GET将它们输出,然后将它们放入变量中。 现在,当我填写错误的表单时,我会被重定向,但所有参数都丢失了,而且它们不再存在于变量中。 有没有办法可以使用相同的参数重定向到同一页面?
重定向后的url: http://localhost:8888/WD2/Week6/Project/flight_bestel.php
由于 enter image description here enter image description here
<?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' ); ?>
答案 0 :(得分:1)
所以你的问题变成了......“我如何重建原始网址作为我的表单的动作”?
一种方法是获取查询字符串并使用它来重建表单“action”。
像...... 抓取原始查询字符串
$query_string = '?'.$_SERVER['QUERY_STRING'];
并将其附加到您的表单操作
<form action= "<?php echo $_SERVER['PHP_SELF'] .$query_string; ?>" method="post" class="form-horizontal">
这应该让你了解你所处理的那个难题。