Re: Type of form element

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, October 30, 2005 5:52 am, Marcus Bointon wrote:
> On 29 Oct 2005, at 20:59, Richard Lynch wrote:
>
>> So you will most likely be using isset($_POST['checkbox_name'])
>> rather
>> than testing for "on"
>
> I classify using isset for checking for the existence of array keys
> to be a bad habit as in some common cases it will not work as you
> expect, for example:
>
> <input type="checkbox" name="checkbox_name" />

A)
If you do not specify a "value=" in HTML for a checkbox, the value is
"on" by default.

So this should give you checkbox_name=on in a GET form.

If it doesn't, your browser is very very very broken.
[Probably Internet Explorer would be the one to get this wrong, if any
of them do]


B)
I dunno what version of PHP you are using, nor what php.ini settings
you have, but, at least in my version/settings:

http://example.com/test.php?checkbox_name=
isset($_GET['checkbox_name']) returns 1

Since HTTP and HTML have no concept of NULL, I'm not real worried that
$_GET will have NULL values in it.

I am certainly not going to pollute $_GET/$_POST/$_REQUEST by stuffing
NULL values into them!

If you want to do things that way, go right ahead.

But I really do believe isset($_POST['checkbox_name']) is a "good"
coding practice.

DSFDD

-- 
Like Music?
http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux