Location: PHPKode > scripts > Validate form elements > example.php
<?php
/**
 * @Osama Salama
 * @copyright 2011,2012
 * @Email hide@address.com
 */


//include class
require_once 'Class.Validate.php';

//create Object From Class
$Object=Validate::getInstance();


if($_POST['submit']){

$array=array(
array('Type'=>'Empty','Var'=>$_POST['email'],'Msg'=>'Enter Value...in email','required'=>true),
array('Type'=>'Email','Var'=>$_POST['email'],'Msg'=>'Invalid Email','required'=>true),
array('Type'=>'IP','Var'=>$_POST['ip'],'Msg'=>'Invalid ip','required'=>true),
array('Type'=>'Int','Var'=>$_POST['old'],'Msg'=>'Invalid int','required'=>true),
array('Type'=>'Url','Var'=>$_POST['url'],'Msg'=>'Invalid url','required'=>true),
array('Type'=>'Upload','Var'=>$_FILES['file1']['name'],'Msg'=>'Chooise file','required'=>true),
array('Type'=>'String','Var'=>$_POST['name'],'Msg'=>'Empty string name....','required'=>true),
array('Type'=>'Extentions','Var'=>$_FILES['file1']['name'],'Msg'=>'Error File Type....','Mime'=>array('PNG','GIF','JPEG','JPG'),'required'=>false)
);

//....
$result=$Object->Valid($array);



if(is_array($result)){
// if is array print Error
foreach($result as $key=>$val){
echo "<li>".$val."</li><br/>";
}
} else {
//else do insert update delete ....as you want..
echo "<h2><font color='green'>OK....Data Submit</font><h2>";
}


}

?>


<!--Html Form-->
<fieldset style="background-color:#CCCCCC; width:250px">
<table>
<form  method="post" enctype="multipart/form-data">

<tr><td>Name :</td><td> <input type="text" name="name"></td></tr>
<tr><td>email : </td><td> <input type="text" name="email"></td></tr>
<tr><td>IP :     </td><td> <input type="text" name="ip"></td></tr>
<tr><td>Int :   </td>  <td><input type="text" name="old"></td></tr>
<tr><td>String :</td><td> <input type="text" name="address"></td></tr>
<tr><td>Url :    </td> <td><input type="text" name="url" /></td></tr>
<tr><td>Upload :</td><td> <input type="file" name="file1" /></td></tr>
 
<tr><td colspan="2" align="center"><input type="submit" value="Send" name="submit"> </td></tr>
 </form></table>
 
 
</fieldset>
<!--/Html Form-->
Return current item: Validate form elements