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.