Page 1 of 1

form name question

Posted: Tue Jun 17, 2003 2:32 pm
by m3rajk
i know to use <input type=checkbox name=bleh[] value =whatever>

but i have a questoni, does it pass ALL values with NULL in place of an unchecked? or does it just pass what's checked? i've found what's written in orielly a little confusing on the subject. the cookbook suggests if you have 5 things you'll have 5 but not all will have a value and the other one suggests that if you have 5 and only 3 are checked, that php will pass an array of 3.

Posted: Tue Jun 17, 2003 3:33 pm
by releasedj
I'm certain that only the checked checkboxes are passed.

Posted: Tue Jun 17, 2003 4:00 pm
by redcircle
releasedj is right.. only checked boxes are checked.

Posted: Tue Jun 17, 2003 4:01 pm
by m3rajk
is there a way to have all the values passed, even if some are null?

Posted: Tue Jun 17, 2003 4:09 pm
by diehuman
I came to this forum looking for this very subject actually.

It will only pass the value if the box is checked. I really wish it didn't do that. I mean, why would it not pass it? That's stupid. It should pass it reguardless.

Anyways.

If someone knows a good work-around for this, let me know. Depending on your situation, you might be able to use hidden inputs to solve your problem. That's what I used.

-Mike

Posted: Tue Jun 17, 2003 4:37 pm
by hedge
One way to do it is to explicitly name your vars with the array index:

instead of

Code: Select all

<input name=var&#1111;]>
<input name=var&#1111;]>

Code: Select all

<input name=var&#1111;0]>
<input name=var&#1111;1]>

Posted: Tue Jun 17, 2003 4:45 pm
by diehuman
m3rajk wrote:is there a way to have all the values passed, even if some are null?
Put a hidden input type above it. If the box does happen to be checked, it will overwrite the hidden input. if the Box is not checked, you'll still get your value and a place in your array if you need that spot to fill the array.

Posted: Tue Jun 17, 2003 4:48 pm
by diehuman
hedge wrote:One way to do it is to explicitly name your vars with the array index:

instead of

Code: Select all

<input name=var&#1111;]>
<input name=var&#1111;]>

Code: Select all

<input name=var&#1111;0]>
<input name=var&#1111;1]>
I don't believe that works. But I was using names, not numbers. So I could be wrong.