[英]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.