首页 > php > 标头()函数中的PHP POST数据

标头()函数中的PHP POST数据 (PHP POST data in header() function)

问题

我有一个表单,要求填写所有信息,我有脚本检查字段是否填写,但我无法弄清楚如何让它重定向回到表单与POST数据来解释错误,是否有这样的方法来做到这一点????

我知道可以使用GET数据这样做,header("Location: index.php?e=1"); 但我想让URL简单地说:

https://foo.bar/index.php 代替 https://foo.bar/index.php?e=1

解决方法

在您的HTML中,您可以编写如下代码:

<input name="name" value="<? echo isset($_POST['name'])? $_POST['name']:"default_value";?>">

//Expecting you submission would be on same page where your have written your HTML content.

问题

I have a form that requires all information to be filled out and I have the script that checks to see if the fields are filled in, but I am unable to figure out how to get it to redirect back to the form with POST data to explain the error, is there such a way to do this????

I know it's possible to do this with GET data like so header("Location: index.php?e=1"); but I want to have the URL simply say:

https://foo.bar/index.php instead of https://foo.bar/index.php?e=1

解决方法

In you HTML you could write code like this :

<input name="name" value="<? echo isset($_POST['name'])? $_POST['name']:"default_value";?>">

//Expecting you submission would be on same page where your have written your HTML content.
相似信息