PHP Radio Buttons形式示例

时间:2015-10-18 19:55:55

标签: php

所以,让我说我有以下示例如何从单选按钮获取值并且acctualy使用这些值?你可以看到我尝试了一些东西,但我无法找到它如何使它工作..

<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <script type="text/javascript" src="js/jquery.min.js"></script>
      <script type="text/javascript" src="js/bootstrap.min.js"></script>
      <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
      <link href="css/bootstrap.css" rel="stylesheet" type="text/css">
   </head>
   <body>
      <div class="navbar navbar-default navbar-static-top">
         <div class="container">
            <div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-ex-collapse"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand">My learning skills: A self-assessment questionnaire</a></div>
            <div class="collapse navbar-collapse" id="navbar-ex-collapse">
               <ul class="nav navbar-nav navbar-right"></ul>
            </div>
         </div>
      </div>
      <div class="section">
         <div class="container">
            <div class="row">
               <div class="col-md-12">
                  <form role="form" method="post">
                     <div class="form-group"><label class="control-label" for="exampleInputEmail1">Nume:</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter name" type="text"></div>
                     <div class="form-group"><label class="control-label" for="exampleInputEmail1">Email address:</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter email" type="email"></div>
                     <div class="container">
                        <div class= "row">
                            <h4>Your gender: *</h4> 
                        </div>
            <div class="row">
             <div class="radio">
              <label><input type="radio" name="gender" value="female">F</label>
            </div>
            <div class="radio">
              <label><input type="radio" name="gender" value="male">M</label>
            </div>
            <div class="radio">
              <label><input type="radio" name="gender" value="other">Other</label>
            </div>
            </div>
            </br>
            <div class="row">
            <div class="form-group"><label class="control-label" for="exampleInputEmail1">Your age: *</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter age" type="text"></div>
         </div>



          <div class= "row">
                            <h2>That was it! Please, keep your scores saved and check that after refilling in this questionnaire, in 6-8 months from now on. Happy learning!</h2>

                        </div>
           <div class= "row">
           <button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg">Send</button>
           </div>
        </div>

                  </form>
                <?php $gender = $_POST['contact']; echo $gender; ?>
               </div>
            </div>
         </div>
      </div>
   </body>
</html>

例如:

回声$性别; 结果应该是女性

1 个答案:

答案 0 :(得分:2)

<?php $gender = $_POST['contact']; echo $gender; ?> 

将此更改为

<?php $gender = $_POST['gender']; echo $gender; ?>. 

您的无线电控制的名称是性别而非联系。