Need help with this form validation Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevinkhan
Forum Newbie
Posts: 9
Joined: Wed Jan 06, 2010 8:08 am

Need help with this form validation Please

Post by kevinkhan »

I have a from with this field in it

<label>Email:</label>
<input type="text" name="email" id="email" />

I want to make sure a user enters the correct format of an email address.. Is there anyway of checking this??

if possible could you right it in this format

Code: Select all

$fields_with_lengths = array('menu_name' => 30);
        foreach($fields_with_lengths as $fieldname => $maxlength)
          {
          if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) 
            {
            $errors[] = $fieldname;
            }
          }
as i want make an error array with all the errors from other fields as well..

Thanks for your help..
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need help with this form validation Please

Post by AbraCadaver »

Not sure what you mean about that format, but here is the basic method:

Code: Select all

if(!filter_var($fieldname, FILTER_VALIDATE_EMAIL)) {
    $errors[] = $fieldname;
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply