form name question
Moderator: General Moderators
form name question
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.
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.
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
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
One way to do it is to explicitly name your vars with the array index:
instead of
instead of
Code: Select all
<input name=varї]>
<input name=varї]>Code: Select all
<input name=varї0]>
<input name=varї1]>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.m3rajk wrote:is there a way to have all the values passed, even if some are null?
I don't believe that works. But I was using names, not numbers. So I could be wrong.hedge wrote:One way to do it is to explicitly name your vars with the array index:
instead ofCode: Select all
<input name=varї]> <input name=varї]>Code: Select all
<input name=varї0]> <input name=varї1]>