Re: ISSET() question



Tony wrote:
major wrote:
The following code processes a blank field as though it has some value
and proceeds as though it was set to some value.

Apparently isset() is not working, because it thinks that a blank text
field is set to something.

Yes, if the value of a field is "", then it is still set. You would want to test for both:

if ( isset($_POST['name']) && ($_POST['name'] != "") ) ...

Or, if you want to count " " as blank:


if ( isset($_POST['name']) && (trim($_POST['name']) != "") ) ...

There may be a more efficient way to do this - anyone know of one?

Yes, validate it with a regex also:

$name = (isset($_POST['name']) && eregi('^[a-zA-Z]${2,25}',$_POST['name'])) ? $_POST['name'] : false;

if (!$name)
{
....
}

would check to see if the post variable has been set and if it matches a string of alpha a-z (upper & lower case), and is at least 2 characters but not more than 25 characters in length. If not it's set to false and you take appropriate action.

--
Norman
Registered Linux user #461062
.



Relevant Pages

  • Re: ISSET() question
    ... Tony wrote: ... and proceeds as though it was set to some value. ... Apparently isset() is not working, because it thinks that a blank text ... would check to see if the post variable has been set and if it matches a string of alpha a-z, and is at least 2 characters but not more than 25 characters in length. ...
    (comp.lang.php)
  • Re: ISSET() question
    ... Tony wrote: ... and proceeds as though it was set to some value. ... Apparently isset() is not working, because it thinks that a blank text ... would check to see if the post variable has been set and if it matches a string of alpha a-z, and is at least 2 characters but not more than 25 characters in length. ...
    (comp.lang.php)
  • Re: ISSET() question
    ... Norman Peelman wrote: ... and proceeds as though it was set to some value. ... Apparently isset() is not working, because it thinks that a blank text ... would check to see if the post variable has been set and if it matches a string of alpha a-z, and is at least 2 characters but not more than 25 characters in length. ...
    (comp.lang.php)
  • Recently Read - August, 2006
    ... Tony Foster finally comes into his own in this better sequel to the OK ... sentimental about her characters. ... a witch-to-be who has to find and murder her doppelganger before she ...
    (rec.arts.sf.written)
  • Re: Magickal Beings
    ... > Tony wrote: ... >> I'm sure Dr. Strange fans can come up with a host of other characters. ... >> After all between Dr. Strange's books and the second Ghost Rider ...
    (rec.arts.comics.marvel.universe)