WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Form Validation Using PHP to highlight non valid fields
Categories : PHP, Form Processing, Data Validation, Beginner Guides
Suraj Thapaliya
Date : May 09th 2006
Grade : 3 of 5 (graded 26 times)
Viewed : 109091
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

This example is used to valid the form data by using php with attractive error message by coloring the text

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
function error_bool($error, $field) {
         if(
$error[$field]) {
             print(
"<td style=color:red>");
         }
        else {
            print(
"<td>");
        }
    }

function
show_form() {
global
$HTTP_POST_VARS, $print_again, $error;
?>

<form action="" method="post">
  <table width="400" border="1" cellspacing="0" cellpadding="0">
    <tr>
     <?php error_bool($error, "name"); ?> Name </td>
      <td><input name="name" type="text" id="name" value="<? echo $_POST["name"]; ?>"></td>
    </tr>
    <tr>
      <?php error_bool($error, "email"); ?> Email </td>
      <td><input name="email" type="text" id="email" value="<? echo $_POST["email"]; ?>"></td>
    </tr>

    <tr>
      <td><input type="submit" name="Submit" value="Submit"></td>
      <td>¬†</td>
    </tr>
  </table>
</form>
<?
}
if(isset(
$_POST["Submit"])) {
   
check_form();
} else {
   
show_form();
}

function
check_email_address($email) {
 
// First, we check that there's one @ symbol, and that the lengths are right
 
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
   
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
   
return false;
  }
 
// Split it into sections to make life easier
 
$email_array = explode("@", $email);
 
$local_array = explode(".", $email_array[0]);
  for (
$i = 0; $i < sizeof($local_array); $i++) {
     if (!
ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
      return
false;
    }
  }
  if (!
ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
   
$domain_array = explode(".", $email_array[1]);
    if (
sizeof($domain_array) < 2) {
        return
false; // Not enough parts to domain
   
}
    for (
$i = 0; $i < sizeof($domain_array); $i++) {
      if (!
ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return
false;
      }
    }
  }
  return
true;
}


function
check_form()
{
global
$HTTP_POST_VARS, $error, $print_again;
$error['name'] = false;
    if(
$_POST["name"]=="") {
       
$error['name'] = true;
         
$print_again = true;
       
$message="The name field is empty<br>";
    }
    if(!
check_email_address($_POST['email'])) {
       
$error['email'] = true;
         
$print_again = true;
       
$message.="Either Field Empty or Invalid Email ID <br>";
    }
     if(
$print_again) {
         
show_form();
       
       } else {
       
show_form();
           
$message="All Fields are valid <br>
        Now, In this way you can validate the other textfield as well<br>
        You can insert data into table"
;
       }
   echo
"$message";
}

?>

</body>
</html>



Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides
Ensure that a specific value lies within a specific range.
Categories : PHP, Beginner Guides, Data Validation
PHP and javascript mouseover, mouseout, and mousedown events
Categories : PHP, Java Script, Form Processing, Beginner Guides
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
Find the day of the week for any given year/month/day.
Categories : PHP, Date Time, Data Validation, Algorithms, Beginner Guides
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
PHP Image Validation Class - test if a specific file is of a certain image type without relying on the said file extension.
Categories : PHP, PHP Classes, Data Validation, Graphics, Beginner Guides
Find if a year is leap.
Categories : PHP, Date Time, Beginner Guides, Data Validation
Form Processing : with alert Highlight field name which is not filled by user
Categories : Java Script, Form Processing, Data Validation, Beginner Guides, Web Design
send php mail with form data and attachment.
Categories : PHP, Email, Mail, Form Processing
How to Insert a Date Format Into MySQL from PHP
Categories : PHP, Databases, MySQL, Date Time, Beginner Guides
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Secure URL $_GET
Categories : PHP, Data Validation, Security
Form Elements Class
Categories : PHP, PHP Classes, Form Processing
 Danilo Dom√≠nguez wrote :1636
Ejemplo sobre validacion de e-mail
Muy bueno