Jump to content

Validations


Terfanda

Recommended Posts

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
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.