简单表单字段的获取

来源:互联网 发布:java区块链开源项目 编辑:程序博客网 时间:2024/05/17 01:33
<html>
<meta charset="utf-8">
<style type="text/css">
.submit{
      border-radius: 45px ;
      border:2px solid #4ab;
      width:60px;
      height:30px;
      font-size: 20px;
      color: red;
}
.form{
     width: 300px;
     height:auto;
    padding: 30px;
    background: #ededed;
    border:2px solid red;
    border-radius: 80px;
}
</style>
<center>
<label><h2 style="color:red">简单的表单数据的显示</h2></label>
<body style="padding-top:100px;width:400px;height:auto;align:center;padding-left:700px;background:#aaa;">
<form method="POST" action=""class="form"" >
<label>爱好:</label>
<input type="checkbox" name="cb[]"id="cb"value="蓝球"/>篮球
<input type="checkbox" name="cb[]"id="cb"value="足球"/>足球
<input type="checkbox" name="cb[]"id="cb"value="排球"/>排球
<input type="checkbox" name="cb[]"id="cb"value="水球"/>水球
</br>
</br>
<label>性别:</label>
<input type="radio"name="sex"value="男"/>男
<input type="radio"name="sex"value="女"/>女
</br>
</br>
<label>所在地:</label>
<select name="selected"size="1">
<option value="-1">请选择...</option>
<option value="安徽省">安徽</option>
<option value="北京市">北京</option>
<option value="湖南省">湖南</option>
<option value="湖北省">湖北</option>
<option value="上海市">上海</option>
</select>
</br>
</br>
<input type="submit"name="Submit"class="submit"value="提交"/>
<input type="reset" class="submit" />
</form>
<?php
if(isset($_POST['Submit']))
{
   if(empty($_POST['cb']))
   {
    echo "<script>alert('爱好不能为空');location.href='".$_SERVER['HTTP_REFERER']."'</script>";
   }
   else
   {
     if(empty($_POST['sex']))
     {
      echo "<script>alert('性别不能为空');location.href='".$_SERVER['HTTP_REFERER']."'</script>";
     }
     else
     {
      if(empty($_POST['selected'])||$_POST['selected']==-1)
      {
      echo "<script>alert('您还没选择所在地呢');location.href='".@$_SEVER['HTTP_REFERER']."'</script>";
      }
      else
      {?>
      <form action=""method="POST"class="form"style="align:left;">
      <?php
        $a=@$_POST['cb'];
        $ab=@implode(" ",$a);
       echo "您选择的爱好是:".$ab;
        echo "</br>";
       echo "您选择的性别是:".@$_POST['sex']."</br>";
       echo "您的所在地是:".@$_POST['selected'];
       ?>
       </form>
      <?php
  }
     }
   }
   }
?>
</center>
</body>
</html>
1 0
原创粉丝点击