Login   Register  
PHP Classes
elePHPant
Icontem

File: Example

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of djomla  >  Form Validation Easy  >  Example  >  Download  
File: Example
Role: Example script
Content type: text/plain
Description: example
Class: Form Validation Easy
Validate posted form values
Author: By
Last change:
Date: 2011-04-25 01:17
Size: 703 bytes
 

Contents

Class file image Download
<?php

include ("FormValidate.php");

## Imagine you have form with two input fields. One name="title" and other name="price". Title must contain 
## alphabetical characters and price must be numeric field. One the user submits form this code is executed

$formValidate = new FormValidate();
$formValidate->setRules(array(
"title" => array("rule" => "not_empty""msg" => "Title is empty"),
"price" => array("rule" => "is_numeric""msg" => "Wrong price")
));

if (
$formValidate->validate()) {
    
// Validation is ok
} else {
    
## Method getErrorMsg() return array of messages that's why you need loop to print all the messages
    
foreach ($formValidate->getErrorMsg() as $fem) {
        echo 
$fem PHP_EOL;
    }
}