form name question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

form name question

Post 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.
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

I'm certain that only the checked checkboxes are passed.
User avatar
redcircle
Forum Commoner
Posts: 43
Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa

Post by redcircle »

releasedj is right.. only checked boxes are checked.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

is there a way to have all the values passed, even if some are null?
diehuman
Forum Newbie
Posts: 5
Joined: Tue Jun 17, 2003 4:09 pm
Location: Kalispell, MT

Post 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
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post 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]>
diehuman
Forum Newbie
Posts: 5
Joined: Tue Jun 17, 2003 4:09 pm
Location: Kalispell, MT

Post 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.
diehuman
Forum Newbie
Posts: 5
Joined: Tue Jun 17, 2003 4:09 pm
Location: Kalispell, MT

Post 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.
Post Reply