开发者

is there a way to pass two values in an input checkbox to the $_POST

I have a bunch of checkboxes on the page and i want to pass two values for each checkbox like this....

<input name="class[]" value="first_value" data="second_value" type="checkbox" class="auto"/>

any idea how to get first_value and second_value past to the $_POST in php

any suggestions on 开发者_JAVA技巧how to do this


You can do this

<input name="class[]" value="CIS 2910C DL:3" type="checkbox" class="auto"/>

where you separate the two values by a : or whatever other separator you want.

Then on the $_POST you can use explode in a loop like this

$pieces = explode(":", $class);
echo $pieces[0]; // CIS 2910C DL
echo $pieces[1]; // 3

so you can pull out both values


You can't do it directly. I'd loop through with jquery and create new hidden inputs with those values and delete the data attr.


How about:

<input name="class[second_value][]" value="first_value" type="checkbox" class="auto"/>

Then in PHP

foreach($_POST['class'] as $first_value=>$tmpArray) {
    foreach($tmpArray as $second_value) {
        echo $first_value.": ".$second_value;
    }
}

Odd way of doing it, but its seems like an odd situation you are in anyways.


I think you can only do this if you use ajax, or if you add a hidden field with an index sequential '[]' buying the checkbox with the value of X in X location hidden

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜