我在页面上有一堆复选框,我想为每个复选框传递两个值,像这样....
<input name="class[]" value="first_value" data="second_value" type="checkbox" class="auto"/>
是否知道如何将first_value
和second_value
传递到php
有什么建议吗
你可以这样做
<input name="class[]" value="CIS 2910C DL:3" type="checkbox" class="auto"/>
用:或其他分隔符分隔两个值。
然后在$_POST中,你可以像这样在循环中使用explosion
$pieces = explode(":", $class);
echo $pieces[0]; // CIS 2910C DL
echo $pieces[1]; // 3
所以你可以拉出两个值
你不能直接这么做。我将使用jquery循环并使用这些值创建新的隐藏输入,并删除数据attr.
如何:
<input name="class[second_value][]" value="first_value" type="checkbox" class="auto"/>
在PHP中
foreach($_POST['class'] as $first_value=>$tmpArray) {
foreach($tmpArray as $second_value) {
echo $first_value.": ".$second_value;
}
}
奇怪的做法,但它似乎是一个奇怪的情况下,你无论如何。
我认为你只能这样做,如果你使用ajax,或者如果你添加一个隐藏的字段与索引顺序'[]'购买复选框的值X在X位置隐藏