<?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;
}
}
|