This study is from: http://www.moke8.com/article-12258-1.html
is based on the Weave Dream CMS form modified to Ajax
The first is the HTML code:
<formAction= "javascript:;"enctype= "Multipart/form-data"Method= "POST"> <inputtype= "hidden"name= "Action"value= "POST" /> <inputtype= "hidden"name= "Diyid"value= "1" /> <inputtype= "hidden"name= "Do"value= "2" /> <label>Name:<inputtype= "text"ID= "Name"name= "Name"value="" /></label> <label>Phone:<inputtype= "text"ID= "Tel"name= "Tel"value="" /></label> <label>Cell phone:<inputtype= "text"ID= "iphone"name= "iphone"value="" /></label> <label>Mailbox:<inputtype= "text"ID= "Email"name= "Email"value="" /></label> <Table> <TR> <TDvalign= "Top">Message:</TD> <TD><textareaID= "Liuyan"name= "Liuyan"></textarea></TD> </TR> </Table> <inputtype= "hidden"name= "Dede_fields"value= "Name,textchar;tel,textchar;iphone,textchar;email,textchar;liuyan,multitext" /> <inputtype= "button"class= "Submit FR"value= "Submit"onclick= "Add_ajaxmessage ()"/></form>
Followed by jquery-based Ajax
/*bind this function to the onclick on the form submission*/functionAdd_ajaxmessage () {
/* Get the Val value of the corresponding element * /varName=document.getelementbyid ("name"); varTel =document.getelementbyid ("tel"); varIphone=document.getelementbyid ("iphone"); varEmail=document.getelementbyid ("Email"); varLiuyan=document.getelementbyid ("Liuyan"); //define variables to receive values for each item in the form above and several Dede hidden input values vardatastring = ' name= ' + name.value + ' &tel= ' + tel.value + ' &iphone= ' + iphone.value + ' &email= ' + Email.value + ' &liuyan= ' + liuyan.value + ' &action=post ' + ' &diyid=1&do=2&dede_fields=name,textchar;tel, Textchar;iphone,textchar;email,textchar;liuyan,multitext '; $.ajax ({type:"POST", URL:"/plus/diy.php",//submit to background fileData:datastring,//Pass ValueSuccessfunction(data) {alert (data);//successfully print the value returned by PHP } }); return false;}
PHP Code:
Found:if(! Empty ($dede _fields)) { // to Add a judgment statement inside, not to judge if($name = = "") {" Please fill in your name! "; // Note: Output with echo output, do not use ShowMsg (); exit (); =!empty ($cfg _cmspath)? $cfg _cmspath: '/'; = ' Publish successfully, please wait for administrator to handle ... '"submitted successfully! "Remove the following sentence: ShowMsg ($bkmsg, $goto);
Ajax Submission Form Method 1