PHP Classes

File: Example

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  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: 4 years ago
Size: 703 bytes


Class file image Download

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();
"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) {
$fem . PHP_EOL;