Required fields for PHP form validation--w3school learning note w3school Offline manual w3school tiy w3school manual Download

Source: Internet
Author: User
Tags php form php form validation
Next, verify the required fields via PHP

Validation rules:
Fields – Validation rules
Name – required, must contain letters and spaces
Email – required, must contain a valid e-mail address, including @ and.
URL (website) – optional, if the fill must be a valid URL
Comment (comment) – optional, multi-line input field
Gender (gender) – required, select an item

HTML code:

<html><head><title> 
     title
 > 
     Head
 ><body><formAction=htmlspecialchars (" 
      echo $_server['php_self'];?>") method= ' post ' > Name:<inputtype=' text 'name=' name ' /><spanstyle=' color:red '>*  
       echo$name _err; ?> 
    
       span
  ><br/>E-Mail:<inputtype=' text 'name=' email ' /><spanstyle=' color:red '>*  
       echo$email _err; ?> 
    
       span
  ><br/>Url:<inputtype=' text 'name=' website ' /><br/>Comments:<textareaname=' comment 'rows=3cols= >  
      textarea
 ><br/>Gender:<inputtype="Radio"name=' gender 'value =0checked=' checked '/>Women<inputtype="Radio"name=' gender 'value=1 / >Men<br/><inputtype=' Submit 'value=' Submit ' /> 
     Form
 > 
     Body
 > 
     HTML
 >

PHP code


    $name=$email=$website=$comment='';$name _err=$email _err='';//Store error messagesif($_server[' Request_method ']==' POST '){if($_post[' name ']==''){$name _err=' The name cannot be empty '; }Else{$name=test_input ($_post[' name ']); }if($_post[' Email ']==''){$email _err=' mailbox cannot be empty '; }Else{$email=test_input ($_post[' Email ']); }$website=test_input ($_post[' website ']);$comment=test_input ($_post[' comment ']);//Because I have a female selected by default in HTML, so sex does not have to be verified as empty$gender=test_input ($_post[' Gender ']);} functiontest_input($data){$data=trim ($data);$data=stripslashes ($data);$data=htmlspecialchars ($data);return$data;}?>

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP form verification required Fields--w3school learning notes, including the w3school aspects of the content, I hope that the PHP tutorial interested in friends to help.

  • 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.