多个表单从一个按钮提交?

时间:2014-07-10 14:30:34

标签: php html forms

如何通过一个提交按钮将多个表单SUBMITTED/POSTED添加到PHP?是否有一种简单的HTML方法来实现这一目标?我需要在PHP端使用传统的$_POST变量,这就是原因。

实施例

<form class="form-horizontal" method="post">

    // SOme fields

</form>

<form class="form-horizontal" method="post">

    // SOme more fields

</form>


<form class="form-horizontal" method="post">

    // some fields here

    <button type="submit" class="btn btn-success">Stuff</button> // This button posts all three forms!
</form>

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

<form class = "form-horizontal" method = "post>
    <select id = "select" name = "selection">
        <option name = "option_one" value = "html">html</option>
        …
    </select>

    <input type = "checkbox" name = "selected[]" value = "first_value">first</input>
    <input type = "checkbox" name = "selected[]" value = "second_value">second</input>

    <input type = "checkbox" name = "another_selected[]" value = "new_first">another first</input>
    <input type = "checkbox" name = "another_selected[]" value = "new_second">another second</input>
    <input id = "submit" name = "submit" type = "submit"></input>
</form>

然后在PHP中:

$selected = _POST["select"];
$first_checkbox_group = _POST["selected"];
$second_checkbox_group = _POST["another_selected"];

请确保为您提供不同的名称。