输入类型textarea作为“输入”发送到电子邮件;“未定义”;来自php邮件
我使用上面的jquery来验证名为“text”的文本区域。这与其他值一起,将get.ajax发送到php页面以发送电子邮件。电子邮件通过一切正常,但文本区通过“未定义”?有什么想法吗?我需要发布更多的代码吗 编辑: 代码的其余部分: php:输入类型textarea作为“输入”发送到电子邮件;“未定义”;来自php邮件,php,jquery,email,textarea,Php,Jquery,Email,Textarea,我使用上面的jquery来验证名为“text”的文本区域。这与其他值一起,将get.ajax发送到php页面以发送电子邮件。电子邮件通过一切正常,但文本区通过“未定义”?有什么想法吗?我需要发布更多的代码吗 编辑: 代码的其余部分: php: var text = $("input#text").val(); if (text == "") { $("input#text").focus(); alert("Please complete all
var text = $("input#text").val();
if (text == "") {
$("input#text").focus();
alert("Please complete all fields");
return false;
}
完成jquery:
$email = $_REQUEST['email'] ;
$text = $_REQUEST['text'] ;
$name = $_REQUEST['name'] ;
$detail = "Name: ".$name."\nMessage: ".$text;
mail( "xxxxxxxxx", "Subject: Contact Form",
$detail, "From: $email" );
echo "Thank you for getting in touch";
$(“#提交”).live('click',function(){
}))
html:
var name = $("input#name").val();
if (name == "") {
$("input#name").focus();
alert("Please complete all fields");
return false;
}
var email = $("input#email").val();
if (email == "") {
$("input#email").focus();
alert("Please complete all fields");
return false;
}
var text = $("input#text").val();
if (text == "") {
$("input#text").focus();
alert("Please complete all fields");
return false;
}
var dataString = 'name=' + name + '&email=' + email + '&text=' + text;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "mailform.php",
data: dataString,
success: function() {
alert("Thanks, we will be in touch soon");
}
});
return false;
});
名称
电子邮件
查询性质
我有一个类似的问题,我的问题是php代码。试着看一下那里的文本区域是否正确发布
我正在使用它,它非常适合我:
<form method='post' action='mailform.php' class="form">
<p class="name">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
</p>
<p class="email">
<label for="email">E-mail</label>
<input type="text" name="email" id="email" />
</p>
<p class="text">
<label for="text">Nature of Enquiry</label>
<textarea id="text" name="text"></textarea>
</p>
<p class="submit">
<input type="submit" id="submit" value="Send" />
</p>
</form>
不确定发生了什么,就像另一位用户说的,我认为数据传递到php脚本的方式有问题
尝试查看jquery可以提供的$.post
和serialize()
函数:
给你一个想法:
//we need to get our variables first
$email_to = 'xxxxx@yahoo.com'; //the address to which the email will be sent
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message']. "\n\n";
/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
---由于一些检查,看看信息是否正确---
我有一个类似的问题,我的问题是php代码。试着看一下那里的文本区域是否正确发布 我正在使用它,它非常适合我:
<form method='post' action='mailform.php' class="form">
<p class="name">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
</p>
<p class="email">
<label for="email">E-mail</label>
<input type="text" name="email" id="email" />
</p>
<p class="text">
<label for="text">Nature of Enquiry</label>
<textarea id="text" name="text"></textarea>
</p>
<p class="submit">
<input type="submit" id="submit" value="Send" />
</p>
</form>
不确定发生了什么,就像另一位用户说的,我认为数据传递到php脚本的方式有问题
尝试查看jquery可以提供的$.post
和serialize()
函数:
给你一个想法:
//we need to get our variables first
$email_to = 'xxxxx@yahoo.com'; //the address to which the email will be sent
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message']. "\n\n";
/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
---由于一些检查,看看信息是否正确---
可以在发送请求的地方添加javascript行吗?到目前为止,一切看起来都很正常。您可以在发送请求的地方添加javascript行吗?到目前为止,一切正常。谢谢,在Firebug中,帖子中的“文本”是“未定义的”!?任何想法我都添加了一些我在联系人表单中使用的代码。不确定如何解释代码中的问题。以及打印什么“”;显示?感谢这个Chris19-最终解决了这个问题:var text=$(“input#text”).val();应该是textarea#textThank,在Firebug中,帖子中的“文本”是“未定义的”!?任何想法我都添加了一些我在联系人表单中使用的代码。不确定如何解释代码中的问题。以及打印什么“”;显示?感谢这个Chris19-最终解决了这个问题:var text=$(“input#text”).val();应该是text区域#text
if(error == false){
//#contact_form has all the variables that get serialized and sent to the php
and you can get a message back to check if everything went okay.
$.post("your_php_code.php", $("#contact_form").serialize(),function(result){
//and after the ajax request ends we check the text returned
if(result == 'sent'){
//if the mail is sent remove the submit paragraph
$('#cf_submit_p').remove();
//and show the mail success div with fadeIn
$('#mail_success').fadeIn(500);
}else{
//show the mail failed div
$('#mail_fail').fadeIn(500);
$('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
}
});