I got a problem with a custom validation rule in Cake 2.X
I want to check if the entered zipcode is valid and therefore a function in the class zipcode is called from the class post.
But the validation returns false all the time.
Appmodel in class post (rule-3 is 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; } }