如何获得多个输入?

时间:2019-07-09 12:42:23

标签: php html

我想获取多个输入并在以后按下“提交”按钮时使用它们

<!DOCTYPE html>
<html>
   <head>
      <title>Class Details</title>
   </head>
   <body>
      <?php
         $noOfSections=0;
         $sectionNameArray= array();
         $sectioerr="";
         if($_SERVER["REQUEST_METHOD"]=="POST"){
             if(!empty($_POST["noOfSections"]))
                 $noOfSections = $_POST["noOfSections"];
             else
                 $sectioerr="Must Enter Number of Sections";
         }
         ?>
      <form action="classdetails.php" method="POST">
         <p>Enter Number of Sections : </p>
         <input type="text" name="noOfSections">*<?php echo $sectioerr?>
         <input type="submit" name="submit" value="Enter"><br>
      </form>
      <form action="classdetails.php" method="POST">
         //Thats the real area about which I am Asking Questions
         <?php
            if($_SERVER["REQUEST_METHOD"]=="POST"){//it is USED to prosses THE STATEMETS BELOW only when the above Submit Button is pressed 
            echo "<p>Enter Names of Sections : </p><br>";
                for($x=0;$x<$noOfSections;$x++){
                    echo "Enter Name of Section No. ".($x+1)."<br>";
                    echo "<input type=\"text\">*";
                }
                    echo "<input type=\"submit\" name=\"submitnames\"><br>";
            }
            ?>
      </form>
   </body>
</html>

当我按下具有名称属性“ submitnames”的“提交”按钮时,我想获得多个输入

1 个答案:

答案 0 :(得分:0)

尝试在动态输入名称的末尾添加[]。

echo "<input type=\"text\" name=\"names[]"\>*";

编辑:感谢Magnus Eriksson指出我在评论中的错误。