On Dec 2, 2007 1:08 PM, tedd <tedd.sperling@xxxxxxxxx> wrote: > At 12:36 PM -0600 12/2/07, Larry Garfield wrote: > >First of all, using "y" and "n" for boolean values (such as a checkbox) is > >very sloppy. "n" is boolean True. A boolean value should evaluate correctly > >in a boolean context. For that, you should use 1 and 0 for your values. > > > >What I usually do is this: > > > ><input type="hidden" name="foo" value="0" /> > ><input type="checkbox" name="foo" value="1" <?php echo $checked; ?> /> > > > >Then when it gets submitted, foo will get the value of the form element that > >was submitted last that has a value. That is, if the checkbox is checked > >then foo will be 1, otherwise it will be 0. That gives you a nice, clean > boolean value you can rely on being present (mostly <g>). > > Larry: > > Not that you said otherwise, but if the programmer does not set the > value for a checkbox, html will provide values -- that may lead to > confusion for newer programmers. > > See here: > > http://webbytedd.com/bbbb/checkbox/ > > If you will note, without specifically setting the value, html will > return "on". > > Also, I'm sure it's an oversight, but your code above should be: > > <?php if ($foo) echo('checked'); ?> > > Cheers, > > tedd > > -- > ------- > http://sperling.com http://ancientstones.com http://earthstones.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > You don't need to do anything. <input type="checkbox" name="likes_pie" /> When it's submitted: <?php if ($_GET['likes_pie']) // checked else // not -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php