PHP.1 form Processing

Source: Internet
Author: User

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

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.