我一直在试图创建此表单来显示错误或没有页面刷新的确认消息。无刷新联系人表单
我一直在尝试使用jQuery,但没有成功。我的jQuery代码是完全错误的,我试图创建它太多次了。
有人可以请指出我在正确的方向吗?
HTML
<form method="post" action="index.php" autocomplete="on">
<label>Name</label>
<input name="name" placeholder="What is your name?">
<label>Email</label>
<input name="email" type="email" placeholder="Your email please">
<label>Message</label>
<textarea rows="10"name="message" placeholder="What would you like to say?"></textarea>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: removed ';
$to = 'removed';
$subject = 'From: removed';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
?>
您需要使用ajax,并且在'#submit'被推送时阻止提交表单。 – vaso123 2014-10-28 15:02:42
你的jQuery代码在哪里? – Terry 2014-10-28 15:02:58
a,你的jQuery代码在哪里? b,如果你的jQuery不对,那么从头开始,c,有很多在线例子,你可以开始使用它作为参考,有一个良好的开端。 – unixmiah 2014-10-28 15:06:08