PHP Implements simple form code
<?php
$message _name= $message _email= "";
$m _name= $m _email=true;
$name = $email = "";
if ($_server["Request_method"]== "POST")
{
if (Empty ($_post["name"])) {
$message _name= "name is required";
$m _name=false;
}else{
$name =text_input ($_post["name"]);
if (!preg_match ("/^[0-9a-za-z]*$/", $name))
{
$message _name= "Names can only be numbers and letters";
$m _name=false;
}
}
if (Empty ($_post["name"])) {
$message _email= "e-mail is required";
$m _email=false;
}else{
$email =text_input ($_post["email"]);
if (!preg_match ("/("/([\w\-]+\@[\w\-]+\.[ \w\-]+)/", $email))
{
$message _email= "e-mail format is incorrect";
$m _email=false;
}
}
}
function Text_input ($data) {
$data =trim ($data);
$data =stripcslashes ($data);
$data =htmlspecialchars ($data);
return $data;
}
?>
<body>
<table align= "center" width= ">"
<caption>
<form method= "POST" action= "<?php Echo htmlspecialchars ($_server[" php_self "]);? > ">
<tr>
<TD width= ":</td>" > Name
<TD width= "650" >
<input type= "text" name= "name" value= "<?php echo $name;? > ">
<span class= "error" >* <?php echo $message _name;? ></span>
</td>
</tr>
<tr>
<TD width= ":</td>" > E-mail
<TD width= "650" ><input type= "text" name= "email" value= "<?php echo $email;? > ">
<span class= "error" >* <?php echo $message _email;? ></span>
</td>
</tr>
<tr>
<TD width= "$" ><span class= "error" > (note!) "*" indicates mandatory) </span></p></td>
</tr>
<tr>
<td>
<input type= "submitted" name= "submit" value= "Submission" >
</td>
</tr>
<?php
if (Isset ($_post["submit") && $m _name&& $m _email) {
Echo ' <tr><td> ';
echo "Name:". $name;
Echo ' </td></tr> ';
Echo ' <tr><td> ';
echo "e-mail:" $email;
Echo ' </td></tr> ';
}
?>
</form>
</table>
</body>
Report:
<?php
The "I" after the pattern delimiter indicates a search with a case-insensitive letter
if (Preg_match ("/hi/i", "Welcome to Hi-docs.com.")) {
echo "A match was found.";
} else {
echo "A match is not found.";
}
?>
This article is from the "Software Learning Summary" blog, be sure to keep this source http://bigcrab.blog.51cto.com/10626858/1686396
PHP.1 Form processing