PHP Classes

File: example4.php

Recommend this page to a friend!
  Classes of M H Rasel  >  Form Validation  >  example4.php  >  Download  
File: example4.php
Role: Example script
Content type: text/plain
Description: Depends
Class: Form Validation
Validate submitted form values according to rules
Author: By
Last change:
Date: 12 years ago
Size: 3,036 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;
$rules = array(
"Yes"=> array(
"type" => "checkbox" // declering the form field as checkbox
"depend_on" =>"Yes", // set the depend_form field , this rule
                                            // will be checked only when the Yes form field is set.
                                            // other then this entire rule will be escaped
"require" =>true,
"email" => true,
// set the error message
$message = array(
"email"=>"Invalid email address"
$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

<form method="POST" action="">
    <table border="1" width="100%">
            <td>Click the check box to get newsletter in future
            <input type="checkbox" name="Yes" value="OK" <?php echo ($data["Yes"]=="OK"?"Checked":"") ?>></td>
            <td>Email Address:&nbsp; <input type="text" name="email" value="<?php echo $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.