PHP Classes

File: example5.php

Recommend this page to a friend!
  Classes of M H Rasel  >  Form Validation  >  example5.php  >  Download  
File: example5.php
Role: Example script
Content type: text/plain
Description: Custom Rule
Class: Form Validation
Validate submitted form values according to rules
Author: By
Last change:
Date: 12 years ago
Size: 2,745 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
$data = $_POST["data"];
// define the rules
$rules = array(
"LimAge"=>array( // LimAge is an extended rules for check
"format"=>"ddmmyyyy", // other properties for this LimAge

// define the error message
$message = array(
"date1"=>"please enter this value",

// create the instance of the extended validator
$objValidator = new ExtValidator($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


<form method="POST" action="">
    <p align="center">You need to be in the age of 18 to 28</p>
    <table border="1" width="100%">
            <td>Enter your birth date </td>
            <td><input type="text" name="data[date2]" value="<?php echo $data["date2"] ?>" size="20"> (dd/mm/yyyy )</td>
            <td>Enter your marriage Date</td>
            <td><input type="text" name="data[date1]" value='<?php echo $data["date1"] ?>' size="20"> (dd/mm/yy)</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.