[thelist] Form validation function in PHP

jyee jyee at vt.edu
Sat Jun 8 21:15:01 CDT 2002


David,

I'm not sure why you're not simply using

if ($myvar)
{
  // variable is filled and nonempty
} else
{
  // variable is not filled
}

since empty() is just another name for conversion to boolean in PHP, but if
you're looking to do form validation, there's no need to reinvent the wheel.
There's a good article for basic principles at

http://www.devshed.com/Server_Side/PHP/FormValidatorClass/page1.html

and if you do a search for "PHP form validation download class" at
www.google.com, you'll find many solutions ready to download and use.  Trying
to figure out if a variable is filled is one thing.  Trying to figure out if
you have a valid e-mail address or credit card number is quite another.  Good
luck!

Regards,
Jackson Yee
jyee at vt.edu
http://www.jacksonyee.com

----- Original Message -----
From: "David Bindel" <dbindel at austin.rr.com>
To: <thelist at lists.evolt.org>
Sent: Saturday, June 08, 2002 21:23
Subject: [thelist] Form validation function in PHP


> I am trying to write a PHP function that checks to see if a
> specified variable has been set and is not empty so I don't
> have to write a bunch of code for each variable I want to
> check.
>
> I have tried using the isset() and empty() functions to
> check whether $myvar exists and is not empty this using the
> following code, but apparently, PHP cannot evaluate a string
> which is the name of a variable ("$myvar"):
>
> function filled($variable) {
> if (isset(eval($variable)) && !empty(eval($variable))) {
> return true;
> } else {return false;}
> }
> echo filled("\$myvar");
>
> But it gives me this error:
> Parse error: parse error, unexpected T_EVAL, expecting
> T_VARIABLE or '$' in .....
>
> Does anyone know how I can make this function work right?




More information about the thelist mailing list