Quick question on checkboxes

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
McManCSU
Forum Newbie
Posts: 22
Joined: Mon Apr 23, 2007 6:30 pm

Quick question on checkboxes

Post by McManCSU »

Is there a need to use the 'value' attribute for checkboxes? For example, if I have something like this:

Code: Select all

<input name="checkbox" type="checkbox" checked="checked">
Is there a need for the 'value' attribute, since the POST array will have the 'name' if it was checked on page submission (otherwise it wouldn't be there)?
User avatar
dxm
Forum Newbie
Posts: 8
Joined: Fri Jun 29, 2007 5:18 pm
Location: Wales

Post by dxm »

checked is a HTML parameter, it allows you to decide whether the checkbox should be checked by default. It has nothing to do with passing the state to PHP.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do checkboxes even have a value attribute? PHP sees them as either null or 'on' when passed in a form.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Everah wrote:Do checkboxes even have a value attribute? PHP sees them as either null or 'on' when passed in a form.
yes and the value attribute is very helpful when dealing with checkbox arrays...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You know what, I do remember that. I haven;t used checkboxes in probably two years, but I remember passing values in them. Sorry about that.
Post Reply