Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Ok guys i have this form

<input id="valor" name="valor[]" type="checkbox" value="1" />
<input id="valor" name="valor[]" type="checkbox" value="2" />
<input id="valor" name="valor[]" type="checkbox" value="3" />
<input id="valor" name="valor[]" type="checkbox" value="4" />
<input id="valor" name="valor[]" type="checkbox" value="5" />
<input id="valor" name="valor[]" type="checkbox" value="6" />

<input id="result" name="result" type="text" />

what i need is:

When i check any of the checkboxes an array with the format (for example)

1|2|4

is updated in real time inside the result text field, so i can use in php to explode i tryed a lot of thins none works

PS. just passing trough post will not be enough i know if i just post this field i gonna have an array but i need to pass to the result field

thanks in advance

share|improve this question

closed as not constructive by CBroe, Rachel Gallen, flavian, rds, flup May 5 '13 at 10:58

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

1  
if you explode in php you will also get an array, just like in post... maybe you just need to use your post array correctly? –  Robin Manoli May 4 '13 at 23:18

1 Answer 1

up vote 1 down vote accepted

You could easily execute a serialize() function on a form that wraps these checkboxes. The resulting string can be "decoded" in php using the parse_str() function.

A serialized string of all checkboxes being selected would look like this:

valor%5B%5D=1&valor%5B%5D=2&valor%5B%5D=3&valor%5B%5D=4&valor%5B%5D=5&valor%5B%5D=6

Passing that value though parse_str() will give you something similar to this:

[valor] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
        [4] => 5
        [5] => 6
    )     
share|improve this answer
    
do u mind show me a example of that? –  Paulo José Oliveira Rosa May 4 '13 at 23:20
    
There isn't much to be shown... once your users have made their selection, execute a serialize() function on the checkbox elements - the resulting string should be passed through parse_str() once it reaches the server. –  Lix May 4 '13 at 23:33
    
the problem is i have another fields in the form and i need the array only from the ckeckboxes any help? –  Paulo José Oliveira Rosa May 5 '13 at 0:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.