【发布时间】:2013-04-22 13:23:57
【问题描述】:
我在“index.php”中有一个表单,我将使用“submit.php”验证一些文本字段,如果一切正常,它应该使用“submit.php”将字段插入我的数据库。现在,如果“submit.php”检测到错误,它应该回显我存储在“index.php”表单下的数组中的错误:
索引.php:
<form action="submit.php" method="POST">
<input type="text" name="email" />
<input type="text" name="url" />
<input type="submit" name="Submit" value="Continue"/>
</form>
<div class="errorsgohere"><?php //WHAT TO ADD HERE? ?></div>
提交.php:
if(isset($_POST['Submit'])) {
//I validate everything... etc..
if(!empty($errors)) {
echo "<div class='errors'>";
foreach($errors as $error) {
echo $error;
}
echo "</div>";
} else { SubmitDatabase(); //If there are no errors it will proceed }
}
如果可能的话,我如何在不刷新整个页面的情况下回显我在 $error BUT 中的 INDEX.php 中的内容? 提前致谢!
【问题讨论】:
-
您不能在前一页显示错误,但您可以使
submit.php看起来像index.php但有错误,或者只是在同一页上使用$_SERVER['PHP_SELF']进行验证。无需刷新,您需要 AJAX。
标签: php validation echo