【发布时间】:2011-07-27 23:14:32
【问题描述】:
所以我有一个单选按钮组,如下所示:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Choose a pet:</legend>
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked" />
<label for="radio-choice-1">Cat</label>
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">Dog</label>
<input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3" />
<label for="radio-choice-3">Hamster</label>
<input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4" />
<label for="radio-choice-4">Lizard</label>
</fieldset>
</div>
现在,如果我只是提交,我会得到这个 $_POST(注意我有多个 Radio group 问题)
Array
(
[radio-choice-1] => choice-1
[radio-choice-2] => choice-4
[radio-choice-3] => choice-2
[submit] => submit
[PHPSESSID] => 11111111111111111
)
如何在提交之前重组 HTML 或 $_POST 数据使其看起来像这样:
Array
(
[type-1] => radio-choice-1
[answer-1] => choice-1
[type-2] => radio-choice-2
[answer-2] => choice-4
[type-3] => radio-choice-3
[answer-3] => choice-2
[submit] => submit
[PHPSESSID] => 11111111111111111
)
也许 jQuery 作为一个选项?
【问题讨论】:
-
为什么要在提交之前而不是之后进行重组?最好在服务器端执行此操作。为什么你使用choice-X 作为值而不仅仅是数值?
标签: php jquery html post radio-group