联系表单脚本未发送表单 [英] Contact Form Script not sending the form
问题描述
我有一个以前使用过的PHP联系人表单脚本(如下所示),所以我知道它可以工作,但是,因为我已经将html表单隐藏在一个新的jQuery驱动的div中:
(<div class="toggle hidemail" id="drop-button" href=""> Email us here </div>
<div class="hidden hiddenform">
)
上下切换,我似乎根本无法发送该表单,发送时该表单应该淡出然后向用户提供确认消息(如脚本中所示),但是它什么也没做,我不会假设没有人知道这里出了什么问题,这样我就可以再次使用此表格吗?
I have this PHP contact form script (as shown below) which I have used before so I know works, BUT, due to that I have hidden the html form inside of a new jQuery powered div:
(<div class="toggle hidemail" id="drop-button" href=""> Email us here </div>
<div class="hidden hiddenform">
)
that toggles up and down, I cant seem to send the form at all, the form when sent is supposed to fade out then give the user a confirmation message (as shown in the script) but it doesn't do anything, I don't suppose anyone would know whats going wrong here so I can get this form working again?
<?php
$to = 'example@gmail.com';
$subject = 'Company Name';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hello my name is $name.
$message
From $name
my email address is $email
EMAIL;
if($name == '' || $email == '' || $message == "") {
echo "<h5>Sorry, I think you missed bit....</h5>";
$error = true;
} else {
$error = false;
mail("example@gmail.com", $name, $email, $message);
echo "<h5>Thank you for getting in touch. I'll get back to you ASAP.</h5>";
}
if($error == true):
?>
<article id="contact-form">
<article id="load_area">
<form id="my-form">
<input type="text" name="name" placeholder="Name" />
<input type="text" name="email" placeholder="Email" />
<textarea name="message" placeholder="Message" /></textarea>
<input type="button" class="submit_button" value="Send" name="send_button" />
</form>
</article>
</article>
<?php
endif;
?>
这是HTML:
<div class="toggle hidemail" id="drop-button" href=""> Email us here </div>
<div class="hidden hiddenform">
<article id="contact-form">
<article id="load_area">
<form id="my-form">
<input type="text" name="name" placeholder="Name" />
<input type="text" name="email" placeholder="Email" />
<textarea name="message" placeholder="Message" /></textarea>
<input type="button" class="submit_button" value="Send" name="send_button" />
</form>
</article>
</article>
</div>
$(document).ready(function() {
$(".submit_button").live("click", function() {
$("#load_area").fadeOut('slow', function() {
$("#load_area").fadeIn();
$.post("process.php", $("#my-form").serialize(), function(data) {
$("#load_area").html(data);
})
});
})
})
推荐答案
尝试使用
$(".submit_button").on("click", function(){
而不是'$(".submit_button").live("click", function(){
来自jQuery Docs:
From jQuery Docs:
从jQuery 1.7开始,不推荐使用.live()方法
As of jQuery 1.7, the .live() method is deprecated
也尝试使用
$('#my-form').submit(function() {
alert('Handler for .submit() called.');
return false;
});
,然后以html格式设置操作,如下所示:
and set an action in your html form like so:
<form id="my-form" action="process.php">
这篇关于联系表单脚本未发送表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!