PHP Classes

File: example3.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of M H Rasel  >  Form Validation  >  example3.php  >  Download  
File: example3.php
Role: Example script
Content type: text/plain
Description: Radio & Check box Example
Class: Form Validation
Validate submitted form values according to rules
Author: By
Last change:
Date: 5 years ago
Size: 4,076 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; // collect the data from the form
$rules = array(
"require"=>true, // the user need to u click any of the radio
"type"=>"radio" // in the case of radio button you have add this line inside the rules
"continental"=>"require" // user need to select any of the item

$message = array(
"require"=>"Choose One language" // if user dont select any radio button then it will now work
"continental"=>"Select a continental" // if user dont select any item then this 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


<form method="POST" action="">
    <table border="1" width="100%">
            <td><input type="radio" value="Bangla" id="language" <?php echo ($data["language"]=="Bangla")?"checked ":""?> name="language">Bangla
            <input type="radio" value="English" id="language" <?php echo ($data["language"]=="English")?"checked ":""?> name="language">English
            <input type="radio" value="Others" id="language" <?php echo ($data["language"]=="Others")?"checked ":""?> name="language">Others</td>
            <td>Continental </td>
            <td><select name="continental">
            <option selected value="" >--- Select One ---</option> <!-- this special. by default this item need to be select to work the form validator --!>
            <option <?php echo ($data["continental"]=="Asia")?"selected ":""?> value="Asia">Asia</option>
            <option value="Europe" <?php echo ($data["continental"]=="Europe")?"selected ":""?>>Europe</option>
            <option value="Africa" <?php echo ($data["continental"]=="Africa")?"selected ":""?>>Africa</option>
            <option value="Australia" <?php echo ($data["continental"]=="Australia")?"selected ":""?>>Australia</option>
            <option value="Antertica" <?php echo ($data["continental"]=="Antertica")?"selected ":""?>>Antertica</option>
            <option value="North America" <?php echo ($data["continental"]=="North America")?"selected ":""?>>North America</option>
            <option value="South America" <?php echo ($data["continental"]=="South America")?"selected ":""?>>South America</option>
    <p><input type="submit" value="Check" name="action"><input type="reset" value="Reset" name="B2"></p>