WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Power Form Validation
Categories : PHP, PHP Classes, Data Validation Click here to Update Your Picture
Zeljko Radulovic
Date : Nov 09th 2005
Grade : 3 of 5 (graded 5 times)
Viewed : 12413
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Zeljko Radulovic
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
// File:
// Name: Validation.php
// Date: 2005/11/03 06:30:18
// ----------------------------------------------------------------------
//
// Power Form Validation
// Author: Zeljko Radulovic
// http://pad.pmf.kg.ac.yu/articles/index.php?action=author
// ----------------------------------------------------------------------
// Documentation:http://pad.pmf.kg.ac.yu/am/index.php?action=preg_kursa&co_id=7
// Download:http://pad.pmf.kg.ac.yu/am/index.php?action=preg_kursa&co_id=7
// ----------------------------------------------------------------------
class validation {

    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
*/

/*   EXAMPLE1
*
*
    $username="";
    $password="";
    $password1="";
    $email="";
    $age="";
    $screen="";
    $number="";
    $C1="";
    $C2="";
    $C3="";
*/   
   

/*  EXAMPLE2
*
*
    $username="Yeljko1";
    $password="Peric";
    $password1="";
    $email="dfgdfgf";
    $age="45y";
    $screen="3456";
    $number="10";
    $C1="a";
    $C2="b";
    $C3="";
*/ 
   

/*  EXAMPLE3
*
*
    $username="Yeljkooo";
    $password="Peric";
    $password1="Perici";
    $email="ryeljko2004@yahoo.com";
    $age="456";
    $screen="rrr";
    $number="6";
    $C1="a";
    $C2="b";
    $C3="c";
*/   


/*  EXAMPLE4
*
*
    $username="Yelj";
    $password="Peric";
    $password1="Peric";
    $email="ryeljko2004@yahoo.com";
    $age="45";
    $screen="rrrrrrr";
    $number="6r";
    $C1="a";
    $C2="";
    $C3="";
*/   
     

   
$a =new validation();
   
$a->set_operations("Username",$username,0,3,5,">",5);
   
$a->set_operations("Password",$password,0);
   
$a->set_operations("Again Password",$password1,0);
   
$a->set_operations("Password and Again Password",$password,$password1,2);
   
$a->set_operations("E mail",$email,0,1);
   
$a->set_operations("age",$age ,0,4,5,">",2);
   
$a->set_operations("Screen Name",$screen,0,3,5,"<",5);
   
$a->set_operations("Some Number",$number,5,"=",10);
   
   
$a->val_arr[0]=$C1;
   
$a->val_arr[1]=$C2;
   
$a->val_arr[2]=$C3;
   
$a->set_operations("Sex",$a->val_arr,6,1);
   
   if (
count($a->errors)==0) {
       print(
"Form data's have successfully passed procedure of validation");
    }else{
       
$a->print_errors();
    }
?>



Banknote Validation - A PHP class that provides several methods to quickly validate banknote serial numbers of the following currencies: AUD, CAD, CHF, CNY, EUR, GBP, JPY, USD.
Categories : PHP, PHP Classes, Data Validation, Regexps
Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides
PHP Image Validation Class - test if a specific file is of a certain image type without relying on the said file extension.
Categories : PHP, PHP Classes, Data Validation, Graphics, Beginner Guides
Validator - A PHP class that can can be used for validating Email IDs and Dates
Categories : PHP, PHP Classes, Data Validation, Email, Date Time
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
Object() = Custom __autoload + Singleton. "automagically" instantiates a class and always retuns the same instance of the same class. It's pretty useful when you want to have persistence in objects.
Categories : PHP, PHP Classes, Algorithms
A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
A Timing Class
Categories : PHP, PHP Classes, Date Time
Mssql database Manager
Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes
Returns Yahoo! Address Book and Messenger List as an Array
Categories : PHP, PHP Classes, CURL
PHP Image Class
Categories : PHP, PHP Classes, Multimedia, GD image library
Open and Close your website in fixed times .
Categories : PHP, PHP Classes, Cron, Date Time
A beginner's session handling class
Categories : PHP, PHP Classes, Sessions, Beginner Guides