NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP and empty if form value is 0

Ophir Prusak ophir at prusak.com
Mon Jan 6 10:04:59 EST 2003


I had a similar problem a few years back (like 1996)
I remember doing something like this in my form code:

// this creates a "default" value for the variable
// it MUST come before the checkbox
<input type=hidden name=some_name value=0>

// this is the checkbox
<input type=checkbox name=some_name>

I wouldn't really recomend doing it this way since it's just a hack.
It depends on the variables being set in the order in which they appear in
the URL.
You could probably do something using the same idea, but with arrays that
would be much better.

Ophir

----- Original Message -----
From: "Freedman, Tom S." <tfreedma at ubspw.com>
To: "NYPHP Talk" <talk at nyphp.org>
Sent: Monday, January 06, 2003 9:34 AM
Subject: RE: [nycphp-talk] PHP and empty if form value is 0


> I ran into this myself.  With checkboxes (and radio buttons, I think), the
> form key and value are only passed to the following page if they are
checked
> off.  That is, if Checkbox is checked (and has 'value=1', you will see
> $Checkbox=1.  If Checkbox is not checked, you will see nothing at all, as
if
> Checkbox doesn't exist on the submitted form.  So if you are passing
> checkboxes or radio buttons to a processing page, you really have to check
> for existence, as well as value.  isset(), which Steve pointed out, may
> work... I go about it differently (I set all of my variables explicitly,
> instead of in a loop, so I use 'if ($_GET['checkbox']){$checkData =
> $_GET['checkbox'];}' and such.)
>
> -----Original Message-----
> From: Phil Powell [mailto:soazine at erols.com]
> Sent: Saturday, January 04, 2003 7:28 PM
> To: NYPHP Talk
> Subject: [nycphp-talk] PHP and empty if form value is 0
>
>
> foreach ($HTTP_GET_VARS as $key => $val) {
>    if (!empty($HTTP_GET_VARS["$key"])) ${"$key"} = $HTTP_GET_VARS["$key"];
>   }
>
>   foreach ($HTTP_POST_VARS as $key => $val) {
>    if (!empty($HTTP_POST_VARS["$key"])) ${"$key"} =
$HTTP_POST_VARS["$key"];
>   }
>
> Whenever the form variable is equal to 0, the value is not passed into the
> corresponding variable.
>
> For example, if isLogin = 1, then $isLogin = 1
> But if isRegistered = 0 then $isRegistered = {null}
>
> I do not understand why this happens, someone enlighten me!
>
> Phil
>
>
>
>
>
>
>
> --- Unsubscribe at http://nyphp.org/list/ ---
>
>
>





More information about the talk mailing list