Terfanda Posted June 18, 2006 Share Posted June 18, 2006 HI All i have written this function to create a form function CreateForm() { print("<form action=\"Petition.php\" method=post>\n"); print("First Name :<input type=text name=\"fname\" size=24 maxlength=32>"); print(" Last Name :<input type=text name=\"lname\" size=24 maxlength=32><br>\n"); print(" Email :<input type=text name=\"mailaddress\" size=30 maxlength=60><br>\n"); print("<input type=hidden name=\"BeenSubmitted\" value=\"TRUE\"><br>\n"); print("<input type=submit name=\"submit\" value=\"Submit\"></form>\n"); }I need to know how can validate : fname, lname (check if they are empty or filled with numbers)and check if the email entered is in the correct formThank you in advance Link to comment https://forums.phpfreaks.com/topic/12311-validations/ Share on other sites More sharing options...
michaellunsford Posted June 18, 2006 Share Posted June 18, 2006 I just installed AndyB's captcha script, which includes what you need and an anti-robot security feature. I'd try it first:[a href=\"http://www.digitalmidget.com/php_noob/captcha.php\" target=\"_blank\"]http://www.digitalmidget.com/php_noob/captcha.php[/a]just to check if a field is empty, you can do a few ways. If using $_POST, you can just check for the $_POST variable (if it's empty, a browser typically won't send it), or you could strlen the variable, too.[code]if(!$_POST['fname']) $errorvar.="no first name\n";if(!$_POST['lname']) $errorvar.="no last name\n";if(!$_POST['email']) $errorvar.="no email address\n";[/code]checking email address is a bit more complex... Here's a snipit from AndyB's script:[code] if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $err.= $email. " is not a valid email address.<br/>"; }[/code]hope that helps. Link to comment https://forums.phpfreaks.com/topic/12311-validations/#findComment-47048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.