我有一个电子邮件表单,我正在验证一个日期,这是一个预订表单。我所做的是,当开始日期大于结束日期时,它会给我一条消息,说要修改日期并重定向到页面。我有两个页面,即预订表格的页面,当我点击提交时,它会转到contact_engine页面以验证并发送电子邮件:
我是这样说的:
if ($datebegin >= $dateend){
echo '<script>alert("Fix the Date");</script>';
exit;
问题是,当它退出时,它会停留在函数页中,我希望它退出,但转到上一页。有人能帮我吗?我尝试使用exit
。我试着把它和header("Refresh: 1; url=http:/website.com/booking.php");
一起使用,但不知怎么的,这把我带到了sent_page_booking page
。
我建议一种替代方法:处理表单提交和验证的正确方法是使用Post Redirect Get技术:
- 用户提交表单(即POST请求)
- 表格有效吗?如果是,请处理它,并使用GET将重定向到确认页面
- 如果表单无效,只需显示带有错误消息的表单(作为对原始POST请求的响应)
举例说明:
+--------+ POST +--------+ Yes +----------+ GET +--------------+
| Submit | -------> | Valid? | -------> | Redirect | ------> | Confirmation |
+--------+ +--------+ +----------+ +--------------+
^ |
| | No
+-------------------+
使用此:
header("Location: phppage.php");
并且在此代码之前不要使用CCD_ 4。把这个代码放在启动中,用按钮事件调用它。
如何进行定时重定向,以便用户获得显示的错误消息:
header("refresh:5;url=back-to-booking-form.php");
echo 'Form Error. Fix the date. Redirecting to the booking form in about 5 secs.';
使用下面的链接来准确回答
https://stackoverflow.com/questions/13539752/redirect-function
function redirect_url($path)
{
header("location:".$path);
exit;
}