class - Cake PHP custom validation rule -
i got problem custom validation rule in cake 2.x
i want check if entered zipcode valid , therefore function in class zipcode called class post.
but validation returns false time.
appmodel in class post (rule-3 it):
'deliveryarea' => array( 'rule-1' => array( 'rule' => array('between', 5, 5), 'message' => 'bitte eine fünfstellige postleitzahl eingeben' ), 'rule-2' => array( 'rule' => 'numeric', 'message' => 'bitte nur zahlen eingeben' ), 'rule-3' => array( 'exists' => array( 'rule' => 'zipexists', 'message' => 'postleitzahl existiert nicht!' ) ) ),
appmodel in class zipcode:
class zipcode extends appmodel { var $name = 'zipcode'; var $validate = array( 'zipcode' => array( 'length' => array( 'rule' => array('maxlength', 5), 'message' => 'bitte einen text eingeben' ), 'exists' => array( 'rule' => array('zipexists'), 'message' => 'postleitzahl existiert nicht!' ) ) ); function zipexists($zipcode){ $valid = $this->find('count', array('conditions'=> array('zipcode.zipcode' =>$zipcode))); if ($valid >= 1){ return true; } else{ return false; } }
i hope it´s stupidly easy? in advance
i think this:
'zipcode.zipcode' =>$zipcode
...needs this:
'zipcode.zipcode' =>$zipcode['zipcode']
Comments
Post a Comment