value var $elements; // field => type var $error_data; // field, var $error_messages; //filed => message function CFormProcessor($i_fromdata, $strip_sl = FALSE) { $this->form_data = $i_fromdata; if($strip_sl) // STRIP SLASHES foreach($this->form_data as $k=>$v) $this->form_data[$k]=stripslashes($v); } function SetElementTypes($i_types) { $this->elements = $i_types; } function SetErrorMessages($i_messages) { $this->error_messages = $i_messages; } function ValidateType($content, $i_type) { /// TEXT:MIN:MAX ////////////// if(ereg("text:([0-9]+):([0-9]+):(TRUE|FALSE)", $i_type, $regs)) { if($regs[3]=="FALSE" && strlen($content)==0) return TRUE; return ( strlen($content)>=$regs[1] && strlen($content)<=$regs[2] ); } /// INT:MIN:MAX /////////////// elseif(ereg("int:([0-9]+):([0-9]+):(TRUE|FALSE)", $i_type, $regs)) { if($regs[3]=="FALSE" && strlen($content)==0) return TRUE; return ( ereg("^[0-9]+$",$content) && $content>=$regs[1] && $content<=$regs[2] ); } /// FLOAT:MIN:MAX:AFTER POINT MIN:MAX ///// elseif(ereg("float:([0-9\.]+):([0-9\.]+):([0-9]+):([0-9]+):(TRUE|FALSE)", $i_type, $regs)) { if($regs[5]=="FALSE" && strlen($content)==0) return TRUE; if(!is_numeric($content)) return FALSE; ereg("^([0-9]+)\.([0-9]+)$", $content, $r); $after_point = floatval($r[2]); return ($content>=$regs[1] && $content<=$regs[2] && $after_point>=$regs[3] && $after_point<=$regs[4]); } /// EMAIL ///////////////////// elseif(ereg("email:(TRUE|FALSE)", $i_type, $regs)) { if($regs[1]=="FALSE" && strlen($content)==0) return TRUE; return preg_match("/^[a-z][a-z0-9_\-]*(\.[a-z][a-z0-9_]*)?@([a-z0-9_\-]*\.){1,3}([a-z]{2,4})(\.[a-z]{2})?$/ix", $content); } /// IP //////////////////////// elseif(ereg("ip:(TRUE|FALSE)", $i_type, $regs)) { if($regs[1]=="FALSE" && strlen($content)==0) return TRUE; return preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $content); } /// CURRENCY - 0.00 /////////// elseif(ereg("currency:(TRUE|FALSE)", $i_type, $regs)) { if($regs[1]=="FALSE" && strlen($content)==0) return TRUE; return ereg("^[1-9]{1}[0-9]*[.]{1}[0-9]{2}$",$content); } /// FILE:MIN_SIZE:MAX_SIZE elseif(ereg("file:([0-9]+):([0-9]+):(TRUE|FALSE)", $i_type, $regs)) { if($regs[3]=="FALSE" && strlen($content)==0) return TRUE; return ( filesize($content)>=$regs[1] && filesize($content)<=$regs[2] ); } /// IMAGE:MIN_SIZE:MAX_SIZE:MIN_WIDTH:MAX_WIDTH:MIN_HEIGHT:MAX_HEIGHT:TYPE // // 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, // 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), // 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF // elseif(ereg("image:([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9,]+):(TRUE|FALSE)", $i_type, $regs)) { if($regs[8]=="FALSE" && strlen($content)==0) return TRUE; $r_size_min = $regs[1]; $r_size_max = $regs[2]; $r_min_width = $regs[3]; $r_max_width = $regs[4]; $r_min_height = $regs[5]; $r_max_height = $regs[6]; $r_types = explode(",",$regs[7]); $arr = @getimagesize($content); if(!count($arr)) return FALSE; $width = $arr[0]; $height = $arr[1]; $image_type = $arr[2]; return (@filesize($content) >= $r_size_min && @filesize($content) <= $r_size_max && $width >= $r_min_width && $width <= $r_max_width && $height >= $r_min_height && $height <= $r_max_height && in_array($image_type, $r_types) ); } else return false; } function Validate() { foreach($this->elements as $field=>$type) { if(!$this->ValidateType($this->form_data[$field], $type)) { $this->error_data[]=$field; } } return !count($this->error_data); } function GetCaptionPlaceholders($i_prefix, $i_true_value, $i_error_value) { $placholders = array(); if(is_array($this->form_data)){ foreach($this->form_data as $field=>$data){ $placeholders[$i_prefix.$field] = $i_true_value; } }else if(is_array($this->elements)){ foreach($this->elements as $field=>$data){ $placeholders[$i_prefix.$field] = $i_true_value; } } if(is_array($this->error_data)) foreach($this->error_data as $k=>$field) $placeholders[$i_prefix.$field] = $i_error_value; return $placeholders; } function GetData() { return $this->form_data; } function GetErrorMessage($i_delim="
") { if(!count($this->error_data)) return ""; $flat=array(); foreach($this->error_data as $v) if(!empty($this->error_messages[$v])) $flat[]=$this->error_messages[$v]; return @implode($i_delim, $flat); } } ?>