如何通过一个提交按钮将多个表单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>
答案 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"];
请确保为您提供不同的名称。