[英]PHP : how to return back to previous page while closing pop up
I have a form submission. 我有一个表单提交。 While i Click Submit button, will check for mandatory fields and if the fields are blank, I am opening a popup window using javascript to show error message.
当我单击“提交”按钮时,将检查必填字段,如果这些字段为空白,我将使用JavaScript打开一个弹出窗口以显示错误消息。 So once I close the popup I am not going back to previous page Instead it shows a white blank screen.
因此,一旦关闭弹出窗口,我就不会返回上一页,而是显示一个白色的空白屏幕。
My code for verification and opening popup is : 我的验证和打开弹出窗口的代码是:
<?php
if (isset($_POST['submit']))
{
if ($task == '' || $comments == '')
{
// generate error message
print "<script type='text/javascript'>";
print "window.open('error.php','new_window1','status=1,scrollbars=1,resizable=0,menu=no,width=320,height=220');";
print "</script>";
}
else
{
$sql3= "INSERT INTO work (task, comments, assignee, type, priority, dataum1, dataum2, status) VALUES ('$task', '$comments', '$assignee', '$type', '$priority', '$dataum1', '$dataum2', '$status')";
mysqli_query($mysqli,$sql3) or die(mysqli_error($mysqli));
}
}
?>
由于您使用的是JS弹出窗口,因此您可能希望使用JavaScript进行客户端强制检查(尽管也要进行服务器端检查),然后在未填写必要字段的情况下阻止表单发布出来。
Post the form data to the same page where you have the form. 将表单数据发布到具有表单的同一页面上。 And add the above validation code to the top of that page.
并将上面的验证代码添加到该页面的顶部。 So when a validation error occurs, the user sees a popup with the error message, but he is on the same page where the form is.
因此,当发生验证错误时,用户会看到带有错误消息的弹出窗口,但他在表单所在的同一页面上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.