PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of M H Rasel  >  Form Validation  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Date & Email Example
Class: Form Validation
Validate submitted form values according to rules
Author: By
Last change:
Date: 12 years ago
Size: 3,057 bytes


Class file image Download
  * -------------------------------------------------------------------------
  * PHP Form Validator (formvalidator.php)
  * Version 1.0
  * -------------------------------------------------------------------------
  * @author M H Rasel
  * 4-5-2009::0:15
  * @copyright 2009
  * Documentation:
require "";
// if form is posted
//// if form is posted
$data = $_POST['data']; // collect the data from the form

$rules = array(
"date1"=>"date", // check the field data for valid data with default format mm/dd/yy
"format"=>"ddmmyyyy" // check the field data with date format dd/mm/yyyy
"email"=>"email", // check the field for valid email address

// for date1 field if any error found then default error messege for date will be shown
$message = array(
"format"=>"Unsupported Data format" // if the date is not valid according to the given format this error messee will sho
"email"=>"Invalid Email Address", // if email address is not correct then this messege will shown

// create the instance
$objValidator = new Validator($rules,$message);

"<h2><a href='#'>Validator Result </a></h2>";
// call the validation proce
// error found
    // get the list of form fields which have errorful data
$errors = $objValidator->ErrorFields();
// show the number of error
echo "<br/> you have total ".$objValidator->CountError()." errors.<br/>Fields are :".implode(",",$errors);
$errors as $key=>$var)
"For the field <b>$var</b> errors are: ";
// collect error for each error full field
$value = $objValidator->getErrors($var);
// if the field have more then one validation rule faild then an array will return
echo implode(" * ",$value);
        else echo
else echo

<h2> Fill The Following Form </h2>
<form method="POST" action="">
    <table border="1" width="100%">
            <td>Enter a date (in default date format - mm/dd/yy )</td>
            <td><input type="text" name="data[date1]" size="20"></td>
            <td>Enter a date (in dd/mm/yyyy formate)</td>
            <td><input type="text" name="data[date2]" size="20"></td>
            <td>Email: </td>
            <td><input type="text" name="data[email]" size="20"></td>
    <p><input type="submit" value="Check" name="action"><input type="reset" value="Reset" name="B2"></p>

For more information send a message to info at phpclasses dot org.