<!DOCTYPE HTML>
<html>
<body>
<?php
$data=" ";
$name = $email= $website1 = $comment = $gener = " ";
$nameerr = $emailerr = $gendererr = $websiteerr = " ";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
if(empty($_POST["name"])){
$nameerr="must write";
}
else {
$name = test($_POST["name"]);
if(!preg_match("/^[a-zA-Z ]*$/",$name)) //是否只有字符和空格
{
$nameerr = "仅支持母和空格!";
}
}
if(empty($_POST["email"])){
$emailerr="must write";
}
else {
$email = test($_POST["email"]);
if(!preg_match("/([w-]+@[w-]+.[w-]+)/",$email)) //是否有@和.字符
{
$emailerr = "邮件格式不对!";
}
}
$website1 = test($_POST["website"]);
if (!preg_match("/(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%=~_|]/i",$website1)) //www.baidu.com
{
$websiteerr = "网站的格式不对";
}
$comment = test($_POST["comment"]);
if(empty($_POST["gender"])){
$gendererr = "must write";
}
else {
$gener = test($_POST["gender"]);
}
}
function test($data)
{
$data = trim($data);//去掉多余的空格 换行
$data = stripslashes($data);//去掉多余的 /
$data = htmlspecialchars($data);//转化为html实体
return $data;
}
?>
<h1>please input your informmation.....</h1>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> " method="post">
Name: <input type="text" name="name" values="<?php echo $name ;?>"> <span class="error"> * <?php echo $nameerr ;?></span><br><br>
E-mail: <input type="text" name="email" values="<?php echo $email ;?>"> <span class="error"> * <?php echo $emailerr ;?></span><br><br>
Website: <input type="text" name="website" values="<?php echo $website ;?>"> <span class="error"> * <?php echo $websiteerr;?></span><br><br>
comment: <textarea name="comment" rows="5" cols="40" values="<?php echo $comment;?>"> </textarea> <br>
gener:<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female"> Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male <span class="error"> * <?php echo $gendererr ;?></span> <br>
<input type="submit" <?php echo "登陆" ?>> <br>
</form>
<?php
echo "informmation:<br>";
echo $name;
/*echo "<br>";
echo $email;
echo "<br>";
echo $website1;
echo "<br>";
echo $comment;
echo "<br>";
echo $gener;
//<span class="error"> * </span>组合一些信息*/
?>
</body>
</html>