Submit Form form via PHP JQ Ajax

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.