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

Freedman, Tom S. tfreedma at
Mon Jan 6 09:34:23 EST 2003

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]
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!


--- Unsubscribe at ---

More information about the talk mailing list