Reference http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2013/0619/13568.html
Html
<div id= "Contact_form" >
<form name= "Contact" method= "POST" >
<label for= "name" id= "Name_label" > Name </label>
<input type= "text" name= "name" id= "name" size= "" value= "class=" Text-input "/>
<label class= "error" for= "name" id= "Name_error" > This entry is required </label>
<label for= "Email" id= "Email_label" > Your email</label>
<input type= "text" name= "email" id= "email" size= "" value= "" class= "Text-input"/>
<label class= "error" for= "email" id= "Email_error" > this is required </label>
<label for= "Phone" id= "Phone_label" > Your contact number </label>
<input type= "text" name= "phone" id= "phone" size= "" value= "class=" Text-input "/>
<label class= "error" for= "Phone" id= "Phone_error" > This entry is required </label>
<br/>
<input type= "button" name= "Submit" class= "button" id= "submit_btn" value= "I want to send"/>
</form>
</div>
JS
<scriptLanguage="JavaScript">
$(function () {
$(". Error").Hide ();
$(". Button").Clickfunction () {
var name=$("#name").Val ();
if (name==""){
$("#name_error").Show3600);
$("#name_error").Focus ();
return False;
The function of return false is to make the input box effect appear only one at a time
When type is submit, the form form is submitted without return false, and no effect
When type is a button, you can display the effect without return false
Exact words: The error occurs only when an error occurs, which is null, because there is a return of false, and only one error occurs at a time.
}
var email=$("#email").Val ();
if (email==""){
$("#email_error").Show3600);
$("#email_error").Focus ();
return False;
}
var phone=$("#phone").Val ();
if (phone==""){
$("#phone_error").Show3600);
$("#email_error").Focus ();
return False;
}
var datastring =' name= ' + name +' &email= ' + email +' &phone= ' + phone;
document.write (datastring);
$.Ajax ({
Type"POST",
Url:"Text7.php",
Data:datastring,
SuccessFunction (MAG) {
Alert (mag); return;
Ajax Submission Form form PHP can not see the post value, can only be printed in the callback function, following the success of the return effect
$(' #contact_form ').html"<div id= ' message ' ></div>");
$("#message").html"<p> contact information has been successfully submitted! </p> ")
.Append ("<p>script design</p>")
. Hide ()
. fadeIn (), function () {
$ (' #message '). Append (";
});
}
})
return False;
})
})
</script>
Php
Print_r($_post);
$_post[' name '].' <br> '.' I ' m ok!~ "; Die;
Submit Form form via PHP JQ Ajax