Ajax Submission Form Method 1

Source: Internet
Author: User

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

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.