Prosze nie patrzec na sam kod ani ze sa error'y na sztywno bo to sie zmienie lecz na sama logike:
<?php class Validation { protected $type; public $msg; //$fieldname = 'login' //$label = 'Username' //$rules = lenght => 1,4 public function __construct($type = '') { $this -> type = $type; } else { $this -> type = 'post'; } } public function getTypeValidation() { return $this -> type; } public function Submitted() { $submitType = ($this -> getTypeValidation() == 'post') ? $_POST : $_GET; return false; else return true; } $label = $fieldname; } $fieldname = $label; } $submitType = ($this -> getTypeValidation() == 'post') ? $_POST : $_GET; } public function Validation() { foreach($this -> rules as $rule) { foreach($rule as $post => $validRule) { switch($methodRule) { case 'required': if(method_exists(get_class($this), $methodRule)) { $required = $this -> $methodRule($post); } if($required) return true; else { $this -> msg = 'Pole '.$key[0].' nie moze byc puste'; } break; } } } } protected function required($string) { } } ?>
Testuje jak narazie tylko na jednej funkcji analogicznie potem bedzie dzialalo i na reszcie.
No i robie taki maly test:
$_POST['logins'] = 'vodka'; $_POST['haslos'] = ''; $valid = new Validation; $valid -> AddRules('logins', 'username', 'required'); $valid -> AddRules('haslos', 'username', 'required'); $valid -> Validation();
Ten print_r() daje mi:
Cytat
Validation Object ( [type:protected] => post [rules] => Array ( [logins] => Array ( [vodka] => required ) [haslos] => Array ( [] => required ) ) [msg] => )
No i jak widac i msg jest puste i wyswietli mi sie info ze wszystko good.
Gdy ustawie tylko jedna zmienna np logins i ustawie ja jako pusta to dziala wyswietla error dla tego pola lub gdy nie jest puste nie wyswietla wiec robie cos zle w funckji Validation() jednak nie wiem zabardzo co chyba ze ogolnie zle zaprojektowalem tablice z danymi.
Prosze o pomoc i z gory dzieki.
EDIT:
Teraz tak przegladajac post z drugiego kompa zauwazylem ze jest blad:
Powinno byc:
$methodRule = $methodRule[0];
Podajac jednak tylko required jako 3 argument to nic nie zmienia.