Jump to content



  • Please log in to reply
1 reply to this topic

#1 Terfanda

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 18 June 2006 - 06:05 PM

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 form

Thank you in advance

#2 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 18 June 2006 - 06:27 PM

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.
if(!$_POST['fname']) $errorvar.="no first name\n";
if(!$_POST['lname']) $errorvar.="no last name\n";
if(!$_POST['email']) $errorvar.="no email address\n";

checking email address is a bit more complex... Here's a snipit from AndyB's script:
        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/>";

hope that helps.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users