var $val_components =array();
var $val_operations =array();
var $val_arr =array();
var $errors =array();
var $traker =array();
var $name_traker =array();
var $counter;
var $exit_par;
var $a;
function validation(){
$this->val_operations[0]="Controls if is field Empty or if is component selected";
$this->val_operations[1]="Controls with help of Regular Expressions if is e-mail "
." address entered on right way ";
$this->val_operations[2]="Controls if two of entered components have same value";
$this->val_operations[3]="Controls if is entered value in text box in form of letters";
$this->val_operations[4]="Controls if is entered value in text box in form of numbers";
$this->val_operations[5]="lenght";
$this->val_operations[6]="Controls how many components are not selected or in how many "
." of them value is not entered (in case of text field) and "
." compares that number with given value ";
$this->counter=0;
}
function print_operations(){
$a= new print_report($this->val_operations);
$a-> make_report1();
}
function set_operations(){
$this->exit_par=false;
$numargs = func_num_args();
for ($i=2;$i<$numargs;$i++){
switch (func_get_arg($i))
{
case "0":
$name=func_get_arg(0);
$value=func_get_arg(1);
$this->empty_error($name,$value);
break;
case "1":
if (($this->name_traker[$this->counter-1])==func_get_arg(0) and ($this->traker[$this->counter-1])==1 and (func_get_arg(2)==0)) {
break;
}else{
$name=func_get_arg(0);
$value=func_get_arg(1);
$this->email_error($name,$value);
break;
}
case "2":
$name=func_get_arg(0);
$value1=func_get_arg(1);
$value2=func_get_arg(2);
if (trim($value1)=='' or trim($value2)=='') {
break;
}elseif(func_get_arg(2)==2){
break;
}else{
$name=func_get_arg(0);
$value1=func_get_arg(1);
$value2=func_get_arg(2);
$this->same_error($name,$value1,$value2);
break;
}
case "3":
if (($this->name_traker[$this->counter-1])==func_get_arg(0) and ($this->traker[$this->counter-1])==1 and (func_get_arg(2)==0)) {
break;
}else{
$name=func_get_arg(0);
$value=func_get_arg(1);
$this->string_error($name,$value);
break;
}
case "4":
if (($this->name_traker[$this->counter-1])==func_get_arg(0) and ($this->traker[$this->counter-1])==1 and (func_get_arg(2)==0)) {
break;
}else{
$name=func_get_arg(0);
$value=func_get_arg(1);
$this->int_error($name,$value);
break;
}
case "5":
if (($this->name_traker[$this->counter-1])==func_get_arg(0) and ($this->traker[$this->counter-1])==1 and (func_get_arg(2)==0)) {
break;
}else{
$name=func_get_arg(0);
$value=func_get_arg(1);
unset($tr);
$tr=func_get_arg($i+1);
$lang=func_get_arg($i+2);
$this->lang_error($name,$value,$tr,$lang);
$this->exit_par=true;
break;
}
case "6":
$name=func_get_arg(0);
$value=func_get_arg(1);
$num=func_get_arg(3);
$this->arr_error($name,$value,$num);
break;
}
if ($this->exit_par===true) {
break;
}
}
}
function arr_error($name,$value1,$num){
$n=count($value1);
$co=0;
for ($i=0;$i<$n;$i++){
if ($value1[$i]=='') {
$co=$co+1;
}
}
if ($co==$n) {
$this->errors[]="You didn't selected value for field: <b>" .$name. "</b> </br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}else
if ($co < ($n-$num)) {
$this->errors[]="You should selected just ".$num." value for field: <b>" .$name. "</b> </br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}else{
$this->exit_par=true;
}
}
function lang_error($name,$value1,$op,$lang){
$l=strlen($value1);
switch ($op)
{
case "<":
if ($l < $lang) {
$this->errors[]="You didn't enter appropriate value for field: <b>" .$name." </b> this field can not be shorter than ".$lang."</br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
return $this->traker;
break;
}else{
break;
}
case ">":
if ($l > $lang) {
$this->errors[]="You didn't enter appropriate value for field: <b>" .$name. "</b> this field can not be longer than ". " " .$lang."</br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
break;
}else{
break;
}
case "=":
if ($value1 == $lang) {
$this->errors[]="You didn't enter appropriate value for field: <b>" .$name. "</b> this field can not be ".$lang."</br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
break;
}else{
break;
}
}
}
function int_error($name,$value1){
if (eregi("[a-zA-Z/<\/\#$@'$=w+-?>./]",$value1)) {
$this->errors[]="You didn't enter appropriate value for field: <b>" .$name. "</b> this field has to be Number</br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}
}
function string_error($name,$value1){
if (eregi("[0-9/<\/\'$=w+-?>./]",trim($value1))) {
$this->errors[]="You didn't enter appropriate value for field: <b>" .$name. "</b> this field has to be Letters</br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}
}
function empty_error($name,$value){
if (trim($value)=='') {
$this->errors[]="You didn't enter value for field: <b>" .$name. "<b/></br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}
}
function same_error($name,$value1,$value2){
if (trim($value1)!=trim($value2)) {
$this->errors[]="You didn't enter same value for fields <b>" .$name. "<b/></br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}
}
function is_hostname ($host){
if (!eregi("^[a-z0-9]{1}[a-z0-9\.\-]*\.[a-z]{2,}$",$host ))
return false;
if (ereg("\.\.",$host)||ereg("\.-",$host)||ereg ("-\.",$host))
return false;
return true;
}
function is_email($email){
$tmp= split("@",$email);
if (count($tmp)<1)
return false;
if (count($tmp)>2)
return false;
@$username = $tmp[0];
@$hostname = $tmp[1];
if (!eregi("^[a-z0-9_\+\.\-]+$",$username ))
return false;
if(!$this->is_hostname ($hostname))
return false;
return true;
}
function email_error($name,$value1){
if (!$this->is_email($value1)){
$this->errors[]="You didn't enter e-mail on right way <b>" .$name. "<b/></br>";
$this->traker[]=1;
$this->name_traker[]=$name;
$this->counter=$this->counter+1;
$this->exit_par=true;
return $this->traker;
}
}
function print_errors(){
$a= new print_report($this->errors);
$a-> make_report2();
}
}
?>
print_report.php
<?php
class print_report {
var $report_ar =array();
function print_report($par){
$this->report_ar=$par;
}
function make_report1(){
$n=count($this->report_ar);
print("<table width=100 border=1><tr><th colspan=2>Operations</th></tr>");
for ($i=0;$i<$n;$i++){
print("<tr><td> ---index:---".$i."----</td>");
print("<td >".$this->report_ar[$i]."</br></td></tr>");
}
print("</table></br>");
}
function make_report2(){
$n=count($this->report_ar);
print("<table border=1><tr><th colspan=2>Validation Report</th></tr>");
for ($i=0;$i<$n;$i++){
print("<tr><td align=middle >".$this->report_ar[$i]."</br></td></tr>");
}
print("</table>");
}
}
?>
index.php
<?php
include "print_report.php";
include "validation.php";
/*
Here is 4 examples of validating form inputs - only
what you have to do is to let different examples to work.
Complete documentation for this class and one Example you cam find:
http://pad.pmf.kg.ac.yu/am/index.php?action=preg_kursa&co_id=7
*/