> Env:  Slackware 8.1, Apache 1.3.27, PHP 4.3.0
> Bugs: None found for these issues.
> 
> I am running to this same problem.  The isset() function appears to
have
> problems with the empty text value. The empty() function sees the
value
> of $_POST['q1'] as expected.
> 
> So why is both isset() and empty() returning true on q1?

Because the variable is set (isset() TRUE) _and_ it's empty (empty()
TRUE). It means it's a valid variable that has a value of zero or an
empty string (empty string in this case, since it's coming from a form)
 
> I included the is_null() to verify that the value is definitely not
> null.
> 
> Submitting the empty form yields these results:
> Value of q1 ==
> Value of q1 is NOT NULL
> Q1 is empty
> q2 is empty
> q3 is empty
> q4 is empty

These are all correct. I'll explain it below. 

> Values for q2, q3, and q4 all return as expected.
> 
> 
> Source follows:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> <HEAD>
> <TITLE> PHP Test </TITLE>
> <META NAME="Generator" CONTENT="EditPlus">
> <META NAME="Author" CONTENT="">
> <META NAME="Keywords" CONTENT="">
> <META NAME="Description" CONTENT="">
> </HEAD>
> 
> <BODY>
> <FORM action="test.php" method="POST">
>       <span id="q1">Text: <INPUT name="q1" type="text" maxlength="128"
> value=""></span><br>
>       <span id="q2">Radio:
>               <input name="qa2" type="radio" value="1">
>               <input name="qa2" type="radio" value="2">
>               <input name="qa2" type="radio" value="3">
>               <input name="qa2" type="radio" value="4">
>       </span><br>
>       <span id="q3">Checkbox: <input type="checkbox" name="qa3"
> value="9"></span><br>
> 
>       <input type="submit" value="Submit"> <input type="Reset"
> name="Reset"><br>
> 
> </FORM>
> </BODY>
> </HTML>
> 
> PHP Source:
> <?
> 
>       if (isset($_POST['q1'])){
>               print "Value of q1 == ".$_POST['q1']."<br>";
>       }

This will always be true for a text box. When the form is submitted,
$_POST['q1'] will always be set. It's either set to an empty string or
it's set to the value you type in the box.

>       if (is_null($_POST['q1'])){
>               print "Value of q1 is null<br>";
>       } else {
>               print "Value of q1 is NOT NULL<br>";
>       }

This will always be FALSE for a textbox. 

>       if (empty($_POST['q1'])){
>               print "Q1 is empty<br>";
>       }

If you leave the text box empty (empty!) then this will be true. If you
type anything into the box, then this will come out false.

>       if (isset($_POST['q2'])){
>               print "Value of q2 == ".$_POST['q2']."<br>";
>       }

Now... ! checkboxes and radio buttons are a whole different entity. If
you don't select a radio option or check a checkbox, then the variable
is _never set_ at all. So $_POST['q2'] does not exist in your script,
because nothing was selected. So isset() is going to fail.

>       if (empty($_POST['q2'])){
>               print "q2 is empty<br>";
>       }

Now, this is going to come out true, although it really shouldn't.
Technically the variable is empty, because it doesn't exist. The manual
says "no warning is generated when the variable is not set"

>       if (isset($_POST['q3'])){
>               print "Value of q3 == ".$_POST['q3']."<br>";
>       }
>       if (empty($_POST['q3'])){
>               print "q3 is empty<br>";
>       }

Same as above, an unchecked checkbox will cause this variable to never
be created, so it's not set and it's empty.

> 
>       if (isset($_POST['q4'])){
>               print "Value of q4 == ".$_POST['q4']."<br>";
>       }
>       if (empty($_POST['q4'])){
>               print "q4 is empty<br>";
>       }

There is no 'q4' in your form. You did this on purpose, right? It's
going to come out the same way as 'q2' and 'q3', it doesn't exist. So
it's not set and it's empty. 

Hope that clears some things up.

---John Holmes...



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

Reply via email to