PHP form problems

Source: Internet
Author: User
Tags echo 7 php form
PHP form question script
Function formone () {var name = jQuery ("# name "). val (); var url = jQuery ("# url "). val (); var tel = jQuery ("# tel "). val (); var telreg =/^ (\ d {11}) | ^ (\ d {7, 8 }) | (\ d {4} | \ d {3})-(\ d {7, 8}) | (\ d {4} | \ d {3 }) -(\ d {7, 8})-(\ d {4} | \ d {3} | \ d {2} | \ d {1 }) | (\ d {7, 8})-(\ d {4} | \ d {3} | \ d {2} | \ d {1}) $ /; var zw =/^ [\ u4e00-\ u9fa5]/; var ask = jQuery ("# ask "). val (); var des = jQuery ("# des "). val (); if (name = "") {alert ("Enter your name! "); JQuery (" # name "). focus (); return false;} else if (! Zw. test (name) {alert ("Enter the correct name! "); JQuery (" # name "). focus (); return false;} else if (tel =" ") {alert (" Enter your contact number! "); JQuery (" # tel "). focus (); return false;} else if (! Telreg. test (tel) {alert ("Enter the correct contact number! "); JQuery (" # tel "). focus (); return false;} else if (ask =" ") {alert (" Enter your question! "); JQuery (" # ask "). focus (); return false;} else if (! Zw. test (ask) {alert ("Enter the correct question! "); JQuery (" # ask "). focus (); return false;} else if (des =" ") {alert (" Enter your problem description! "); JQuery (" # des "). focus (); return false;} else if (! Zw. test (des) {alert ("Enter the correct problem description! "); JQuery (" # des "). focus (); return false;} else {jQuery. ajax ({url: 'Submit. php', data: {name: jQuery ("# name "). val (), tel: jQuery ("# tel "). val (), ask: jQuery ("# ask "). val (), des: jQuery ("# des "). val (), url: jQuery ("# url "). val ()}, type: 'post', Ype: 'text', success: function (msg) {if (parseInt (msg )! = 0) {alert ("Your problem is submitted successfully and is under review... "); jQuery (" # name "). val (""); jQuery ("# tel "). val (""); jQuery ("# ask "). val (""); jQuery ("# des "). val ("");} else {alert ("Your problem failed to be submitted. please contact us online or call the official phone number 400-600-4936! ");}}})}}

PHP code
 

How can I write script verification into PHP to verify fields?


Reply to discussion (solution)

Write the script verification into PHP to verify the field, which means to convert JavaScript verification into verification in submit. php?

Write the script verification into PHP to verify the field, which means to convert JavaScript verification into verification in submit. php?


Yes. can this be implemented?

The ajax you used was originally thrown into php for operations.

$ Name = stripslashes ($ _ POST ['name']); $ tel = stripslashes ($ _ POST ['tel']); $ ask = stripslashes ($ _ POST ['Ask ']); $ des = stripslashes ($ _ POST ['Des']); $ time = date ('y, m, d, H, I minute, s second ', time (); $ url = stripslashes ($ _ POST ['URL']); $ telreg = '/^ (\ d {11}) | ^ (\ d {7, 8}) | (\ d {4} | \ d {3 }) -(\ d {7, 8}) | (\ d {4} | \ d {3})-(\ d {7, 8 }) -(\ d {4} | \ d {3} | \ d {2} | \ d {1}) | (\ d {7, 8 }) -(\ d {4} | \ d {3} | \ d {2} | \ d {1}) $ /'; $ zw = '/^ [\ u4e00-\ u9fa5]/'; if ($ _ POST) {if ( Empty ($ name) {echo 1;} elseif (! Preg_match ($ zw, $ name) {echo 2;} elseif (empty ($ tel) {echo 3;} elseif (! Preg_match ($ telreg, $ tel) {echo 4;} elseif (empty ($ ask) {echo 5;} elseif (! Preg_match ($ zw, $ ask) {echo 6;} elseif (empty ($ des) {echo 7;} elseif (! Preg_match ($ zw, $ des) {echo 8 ;}else {echo 9 ;}} else {echo 0 ;}


Success: function (msg) {switch (msg) {case 1: alert ('enter your name! '); Break; case 2: alert (' enter the correct name! '); Break; case 3: alert ('Enter your phone number'); break; case 4: alert ('Enter the correct phone number! '); Break; case 5: alert (' enter your question! '); Break; case 6: alert (' enter the correct question! '); Break; case 7: alert ('Enter your problem description'); break; case 8: alert ('Enter the correct problem description! '); Break; case 9: alert ('your problem is submitted successfully and is under review... '); break; case 0: alert ('your problem failed to be submitted. please contact us online or call the official phone number 400-600-4936! ');}}

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.