<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>表单练习</title>
<style>
.content{
width: 300px;
margin:auto;
}
h3{text-align: center;}
.content p select{
width: 70px;
}
</style>
</head>
<body>
<div class="content">
<h3>表单提交</h3>
<form action="p.php" method="post">
<p><label>您的姓名:<input type="text" name="uname" value=""></label></p>
<p><label>您的邮箱:<input type="email" name="email" value=""></label></p>
<p>
您的性别:
<input type="radio" name="gender" id="gender_Male" value="male" checked/>男
<input type="radio" name="gender" id="gender_Female" value="female" />女
<input type="radio" name="gender" id="gender_Shamale" value="shamale" />秘密
</p>
<p>
您的年龄:
<select name="age" id="age">
<option value="1">30一下</option>
<option value="2">30-60</option>
<option value="3">60以上</option>
</select>
</p>
<p align="center"><button type="submit">提交</button></p>
</form>
</div>
</body>
</html>
后台代码
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/12/24
* Time: 19:19
*/
$name = $_REQUEST['uname'] ? $_REQUEST['uname'] : null;
$email = $_POST['email'] ? $_POST['email'] : null;
$gender = $_POST['gender'] ;
$age = $_POST['age'] ;
if (isset($name) || isset($email)){
// echo "<script> alert('{$name}')</script>";
// echo "<script> alert('{$email}');history.go(-1);</script>";
switch ($gender){
case 'male':
break;
case 'female':
break;
case 'shamale':
break;
default:
echo '<script>alert("你的性别没填");history.go(-1);</script>';
}
switch ($age){
case '1':
break;
case '2':
break;
case '3':
break;
default:
echo '<script>alert("你的年龄没填");history.go(-1);</script>';
}
echo '<script>alert("你的表单提交成功");history.go(-1);</script>';
}