我不认为我的标题能解决这个问题,但它可能会让人感到困惑,我不想将标题扩展到几行。
开始:
我有一个单页网站,其中包含带有以下代码的联系表:
<form class="move-down" name="contactform" method="post" action="contact-form-handler.php">
<div class="controls controls-row">
<input id="name" name="name" type="text" class="span3" placeholder="Name">
<input id="email" name="email" type="email" class="span3" placeholder="Email address">
</div>
<div class="controls">
<textarea id="message" name="message" class="span6" placeholder="Your Message" rows="7"></textarea>
</div>
<div class="controls pull-right">
<button id="contact-submit" type="submit" class="btn btn-default">Send it!</button>
</div>
</form>
如您所见,它的作用是调用一个名为“contact-form-handler”的外部 php 文件,如下所示:
<?php
$errors = '';
$myemail = 'hello@wunderful.co.uk';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= die(header('Location: #errorModal'));
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= die(header('Location: #errorModal'));
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' modal
header('Location: #thanksModal');
}
?>
<?php
?>
这一直运行良好,但由于我的新网站是一个页面,我不想加载单独的页面,也不想在白色背景上回显黑色文本。
所以我的问题是 - 单击提交按钮时如何显示引导模式窗口,使用外部文件内部的 php 代码并且不重新加载页面?
我希望它可以做到。如果不能,有人可以帮助我启动一个模式,在单击提交按钮时显示错误或感谢?