[英]submitting form jquery validation plugin
我正在使用jquery验证插件来验证我的Web中的联系表单,但我不知道如何将验证后的表单字段传递到php文件,以将其发送到我的永久电子邮件。
这是我的js代码:
$('#contact-us').validate(
{
rules: {
contactName: {
minlength: 2,
required: true
},
email: {
required: true,
email: true
},
subject: {
minlength: 2,
required: true
},
comments: {
minlength: 2,
required: true
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
}); // end document.ready
我认为我必须使用类似的解决方案,但无法使其正常工作。
有人可以帮助我吗? 提前致谢
您需要在表单的操作部分中的php表单,该脚本的脚本将在表单被验证后运行。
样本联系表html代码
<form method="post" action="submit.php" id="formwa">
<label for="name">Your Name</label>
<input type="text" name="name" id="name" placeholder="Your name here">
<label for="email">Email address</label>
<input type="email" name="email" id="email" placeholder="Enter email">
<button type="submit" class="btn btn-warning">Keep me Updated!</button>
</form>
对应的Submit.php代码
<?php
//$to = $_POST['to'] ;
$message = "Hi there, \n You have a new visitor on your Website.\n\r The person's name is: ".$_POST['name']."\r\n\r\nAnd the person's Email id is: ".$_POST['email'];
$from = $_POST['email'];
$headers = "From: ".$_POST['email'];
mail( "you@yourdomain.com", "Subject Line for the Email", $message, $headers);
// mail( "another@yourdomain.com", "Carbon Copy: Subject Line", $message, $headers);
?>
希望对您有所帮助。 上面的代码没有验证,但是好的,您一直在进行验证本身。 如有更多困惑,请问更多。 干杯
< form action="email.php" >
在表单操作页面中,您可以获得在那里可以发送电子邮件的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.