<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<label>name
<input name= "name" type= "text" id= "name"/>
</label>
<p>
<label>birthday
<input name= "Birthday" type= "text" id= "Birthday"/>
</label>
</p>
<p>
<label>email
<input name= "Email" type= "text" id= "email"/>
</label>
</p>
<p>
<label>
<input type= "Submit" name= "submit" value= "Submit"/>
</label>
</p>
</form>
<?php
This function is primarily used to check whether the submitted form data is wrong (validate)
The actual application of user input data testing (validate) and filtering (filter) are involved in the program security, very important, essential
In writing practical applications will not put the $_post directly in the function, here is a palliative solution, I hope we can correct
if ($_post)
{
Form_error ();
}
function Form_error () {
$_post[' name ' = Trim (strip_tags ($_post[' name ')); This is actually filter
$len _name = strlen ($_post[' name '));
if ($len _name > | | $len _name < 2) {
$msg = ' name length must be greater than 2 30<br/> ';
}
$date = Explode ('-', $_post[' birthday '));
if (sizeof ($date)!= 3) {
$msg. = ' date format error <br/> ';
} else {
if (!checkdate ($date [1], $date [2], $date [0])) {
$msg. = ' Incorrect date <br/> ';
}
}
if (!eregi ("^[a-z ' 0-9]+ ([. _-][a-z ' 0-9]+) *@ ([a-z0-9]+ ([. _-][a-z0-9]+)) +$ ', $_post[' email ']) {
$msg. = ' mailbox format error ';
}
return $msg;
}
?>