index.php:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>表单应用实例</title> </head> <body> <form method="post" name="form1" action="post.php"> <table bgcolor="#bbb" width="500px" border="0"> <caption bgcolor="#bbb"><h3>请输入您的信息</h3></caption> <tr> <td width="100px" align="right" bgcolor="#ddd">姓名:</td> <td width="400px"><input type="text" name="name" value="" bgcolor="#ddd"/></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">性别:</td> <td width="400px"><input type="radio" name="sex" value="男" checked/>男<input type="radio" name="sex" value="女">女</td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">出生年月:</td> <td width="400px"><select name="year"> <?php for ($i=1990; $i <2017 ; $i++) { echo "<option value=".$i."".($i==1998? "selected":"").">".$i."年</option>"; } ?> </select> <select name="month"> <?php for ($i=1; $i <12 ; $i++) { echo "<option value=".$i."".($i==1? "selected":"").">".$i."月</option>"; } ?> </select> </td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">爱好:</td> <td width="400px"> <input type="checkbox" name="interest[]" value="看电影" checked />看电影 <input type="checkbox" name="interest[]" value="听音乐" checked />听音乐 <input type="checkbox" name="interest[]" value="演奏乐器" checked />演奏乐器 <input type="checkbox" name="interest[]" value="打篮球" />打篮球 <input type="checkbox" name="interest[]" value="看书" />看书 <input type="checkbox" name="interest[]" value="上网" />上网 </td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">地址:</td> <td width="400px"><input type="text" name="address" /></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">电话:</td> <td width="400px"><input type="text" name="tel" /></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">QQ:</td> <td width="400px"><input type="text" name="qq" /></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">自我评价:</td> <td width="400px"><textarea name="self" cols="50" rows="5"></textarea></td> </tr> <tr> <td width="100px" bgcolor="#ddd"></td> <td width="400px"> <input type="submit" name="submit" value="提交" /> <input type="reset" name="reset" value="重置" /> </td> </tr> </table> </form> </body> </html>
post.php:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>表单应用实例</title> </head> <body> <form method="post" name="form1" action="post.php"> <table bgcolor="#bbb" width="500px" border="0"> <caption bgcolor="#bbb"><h3>您输入的信息</h3></caption> <tr> <td width="100px" align="right" bgcolor="#ddd">姓名:</td> <td width="400px"> <?php echo $_POST['name'];?></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">性别:</td> <td width="400px"><?php echo $_POST['sex'];?></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">出生年月:</td> <td width="400px"><?php echo $_POST['year']."年".$_POST['month']."月";?> </td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">爱好:</td> <td width="400px"> <?php for ($i=0; $i <count($_POST['interest']) ; $i++) { echo $_POST['interest'][$i]." "; } ?> </td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">地址:</td> <td width="400px"> <?php echo $_POST['address'];?> </td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">电话:</td> <td width="400px"><?php echo $_POST['tel'];?></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">QQ:</td> <td width="400px"><?php echo $_POST['qq'];?></td> </tr> <tr> <td width="100px" align="right" bgcolor="#ddd">自我评价:</td> <td width="400px"><?php echo $_POST['self'];?></td> </tr> </table> </form> </body> </html>