我正在处理表单的脚本,它将数据提交给自己以检查错误,如果没有错误,它使用header()将它们发送到下一页。有没有一种方法可以将$ _POST数据发送到下一页,而不需要重新提交表单?
<?php
if (isset($_POST['submit'])) {
$errors = array();
$moo = array();
if (empty($_POST['a'])) {
$errors[] = 'You forgot to answer Question 1!<br/>';
} else {
$moo = $_POST['a'];
}
if (empty($_POST['b'])) {
$errors[] = 'You forgot to answer Question 2!<br/>';
}
if (empty($_POST['c'])) {
$errors[] = 'You forgot to answer Question 3!<br/>';
}
if (empty($errors)) {
$_POST['aids'] = "RAWR";
$url = "http://localhost/test/test.php?page=2";
header("Location: $url");
exit();
} else {
foreach ($errors as $error) {
echo $error;
}
}
}
echo "
<form action=\"test.php?page=1\" method=\"post\">
<input type=\"text\" name=\"a\" value=\"" . $_POST['a'] . "\">
<input type=\"text\" name=\"b\" value=\"" . $_POST['b'] . "\">
<input type=\"text\" name=\"c\" value=\"" . $_POST['c'] . "\">
<input type=\"submit\" name=\"submit\">
</form>
";
?>
将它保存到文件或数据库? – Dave 2013-03-09 00:38:53
你试过使用'.ajax()'吗? – 2013-03-09 00:40:32
在JS中做错误检查。或者,如果想要scrictly使用PHP,可以将它们保存在会话中并传递。或者,建议的方法是进行错误检查并使用同一文件中的数据。 – Jon 2013-03-09 00:41:31