Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对表单数据有困难_Php_Forms_Submit - Fatal编程技术网

Php 对表单数据有困难

Php 对表单数据有困难,php,forms,submit,Php,Forms,Submit,我有3个文本字段,只有一个提交按钮可以一次发送文本字段的所有数据。但是如何在php中同时发送所有三个文本字段的数据呢 <form> for($x=0;$x<3;$x++){ <input type="text" name="name"> } <input type="submit" name="submit"> </form> 对于($x=0;$x您将它们都放在同一个中,并确保它

我有3个文本字段,只有一个提交按钮可以一次发送文本字段的所有数据。但是如何在php中同时发送所有三个文本字段的数据呢

     <form>
     for($x=0;$x<3;$x++){
     <input type="text" name="name">
     }
     <input type="submit" name="submit">
     </form>


对于($x=0;$x您将它们都放在同一个
中,并确保它们的
名称
属性具有不同的值(或者这些值以
[]
结尾)。

例如,在输入中使用“name”属性可以这样做

<form action='submit.php' method='post'>
    <input type='text' name='one'></input>
    <input type='text' name='two'></input>
    <input type='text' name='three'></input>
    <input type='submit' name='submit' value='Submit!' />
</form>

在PHP中,您可以执行以下操作

<?php
    if(isset($_POST['submit'])){
        $inputOne = $_POST['one'];
        $inputTwo = $_POST['two'];
        $inputThree = $_POST['three'];

        //Do whatever you want with them
    }
?>

有更好的方法可以做到这一点,但这可能是最容易理解的方法


如果希望所有输入具有相同的名称,请执行此操作

<input type='text' name='textinput[]'></input>

使用它,然后像这样循环所有输入

<?php
    foreach($_POST['textinput'] as $input){
        //do something with $input
    }
?>

我相信您要查找的是姓名字段后面的[]注释


查看有关使用PHPCA处理表单的一些基本信息,您可以用代码示例更详细地解释它吗?这太短了,无法回答。我在一个循环中生成了三个字段。现在我想用一个提交按钮提取所有三个字段的数据。我该怎么做?看,我有一个for循环,其中输入标记是s生成了3次现在我想用一个提交按钮从所有三个字段中提取数据。看,我有一个for循环,其中我生成了三次输入字段,现在我必须用一个提交按钮从所有三个字段中提取数据。我怎么做?
<form>
   for($x=0;$x<3;$x++) {
      <input type="text" name="name[]" />
   }
   <input type="submit" name="submit" />
</form>
$names = $_POST['name'];
foreach( $names as $name ) {
   print $name;
}