[英]using modal popup for php redirect
我有一个php邮件表单(工作正常),当前可以重定向到“谢谢”页面。 我正在改造网站,并希望(而不是重定向到另一个页面)(成功提交后)出现一个模式弹出窗口,并说谢谢。 我还需要清除该表单,因为用户将停留在当前页面上。 我已经搜索(包括关于stackoverflow和Web搜索)的解决方案。 我发现了一些“想法”,但没有任何效果。 我目前在网站上的其他内容上使用模式弹出窗口(自改版以来),并且通常了解它们的工作方式。 我对php也有基本的了解。 我在考虑是否有可能在标头中使用某种类型的JavaScript来调用模式弹出窗口。 我也已经看到需要使用AJAX的想法。
任何帮助将不胜感激。
这是我的HTML表格:
<p class="formrequired">Required fields are marked with an asterisk(*)</p>
<form action="form.php" method="post">
<ol class="forms">
<li><label for="first_name">*First Name</label><input type="text" name="first_name"/></li>
<li><label for="last_name">Last Name</label><input type="text" name="last_name"/></li>
<li><label for="email">*Email</label><input type="text" name="email"/></li>
<li><label for="comment">*Message</label><textarea name="comment"cols="45" rows="5"></textarea></li>
<li><input type="submit" value="Submit" class="submit"/>
</ol>
</form>
和我的PHP:
<?php
$myemail = "person@email.com";
$first_name = check_input($_POST['first_name'], "Please enter your first name");
$last_name = check_input($_POST['last_name']);
$email = check_input($_POST['email']);
$comment = check_input($_POST['comment'], "Please enter your message");
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address is not a valid email address");
}
$subject="New form submitted on Napoleonville Fire";
$message = "Hello Jordy!
Your contact form has been submitted by:
First Name: $first_name
Last Name: $last_name
E-mail: $email
They left the following message:
$comment
End of message.
";
mail($myemail, $subject, $message);
header('Location: thankyou.html');
exit();
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
再次感谢您提供的所有帮助。
如果可以解决,我将有一个“第2部分”。
我能想到的两个流程
非AJAX
像现在一样将表单提交到服务器。 然后,在重新显示成功页面时,渲染带有模式显示的页面。 提供某种关闭按钮,该按钮在其上不显示任何内容或将其完全从DOM中删除。 通过这种方法,您可以使用PHP处理呈现空表单。 这是更传统的范例。
AJAX
为此,将事件处理程序添加到表单提交中。 通过AJAX提交表单,但不要立即清除表单字段。 等待服务器的响应。 例如,如果服务器在表单提交中发现验证错误,则必须更新表单以反映此错误。 如果服务器返回成功响应,请使用Javascript清除表单字段并显示模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.