SV: [PHP4BETA] isset(checkbox) vs. isset(text)
| From: | Johan Ekenberg | Date: | Mon, 21 Feb 2000 12:55:12 +0000 |
| Subject: | SV: [PHP4BETA] isset(checkbox) vs. isset(text) | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10572@lists.php.net to get a copy of this message | ||
> Johan Ekenberg wrote:
>
> > Excuse the repost. I'm really curious if someone has an answer
> > to this:
> >
> > It appears that a named input field of type "text" will always
> > set a $GLOBALS[]variable in PHP4 (even if it's empty), while a
> > named checkbox will only set the corresponding $GLOBALS[] variable
> > if it is checked.
> >
> > --
> > <INPUT TYPE='text' NAME='text' VALUE=''> // empty
> > <INPUT TYPE='checkbox' NAME='checkbox' VALUE='1'> //
> > unchecked
> > --
> >
> > When submitting the above, both formfields empty/unchecked,
> > this will be the result in PHP:
> >
> > isset($GLOBALS[text]); // = true
> > isset($GLOBALS[checkbox]); // = false
> >
> > Is it meant to be this way?
> > If so, could somebody please explain why?
> > I find the above behaviour inconsistent, but perhaps
> > I'm missing the obvious reason?
> >
> > In my mind any named form field should be returned as a
> > set variable regardless of whether it has a value or not.
> >
> > /Johan Ekenberg
> >
>
> if a variable for your checkbox should be created, which value would you
> expect
> if the user sends it unchecked??
I'd expect it to have an empty value, ie the empty string.
There are IMHO at least 2 problems with the current behaviour:
1. It's inconsistent. If an unchecked checkbox doesn't define a
variable, an empty <input type='text'> shouldn't define one either.
2. Since "definedness" is not consistently handled, one
can not use this to check dynamically created HTML forms for their
actual FORM fields.
Best regards,
/Johan Ekenberg