Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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
Javascript 对PHP表单数组使用HTML字段集_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 对PHP表单数组使用HTML字段集

Javascript 对PHP表单数组使用HTML字段集,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我知道您可以将名称数组用于多个表单输入(例如,),但这也可以用于整个字段集吗?如何使用PHP$\u POST global进行操作 以下是我正在尝试做的: <fieldset name="player[]"> <input type="text" name="username"> <input type="number" name="points"> </fieldset> <fieldset name="player[]">

我知道您可以将名称数组用于多个表单输入(例如,
),但这也可以用于整个字段集吗?如何使用PHP$\u POST global进行操作

以下是我正在尝试做的:

<fieldset name="player[]">
  <input type="text" name="username">
  <input type="number" name="points">
</fieldset>

<fieldset name="player[]">
  <input type="text" name="username">
  <input type="number" name="points">
</fieldset>


我之所以尝试这样做,是因为我正在构建一个表单,允许用户动态添加/减去“player”FieldSt.如果你有一个比我要求的更好的解决方案,请随意提供一个备选方案。

< P>另一方面,如果你想要这样的分组,你可以在你的表单中创建一个分组,例如:考虑这个例子:

<form method="POST" action="">
    <fieldset>
        Username: <input type="text" name="player[0][username]" />
        Points: <input type="number" name="player[0][points]" />
    </fieldset>

    <fieldset>
        Username: <input type="text" name="player[1][username]" />
        Points: <input type="number" name="player[1][points]" />
    </fieldset>


    <br/>
    <input type="submit" name="submit" />
</form>

因此,字段集除了分离表单内容外,在功能上没有任何作用?@Jason本质上,它对其他功能没有帮助,因为表单用于适当的语义目的。为字段集提供了良好的上下文
if(isset($_POST['submit'])){
    $all_players = $_POST['player'];
    echo '<pre>';
    print_r($all_players);
    echo '</pre>';
}
Array
(
    [0] => Array
        (
            [username] => Test1
            [points] => 1
        )

    [1] => Array
        (
            [username] => Test2
            [points] => 2
        )

)