cakephp - Cake PHP validation error not shown although existing in array -
after having trouble calling validation functions in model, tried validating controller. works fine except 1 field value wrong not shown red , doesn´t show error-message.
the "validationerrors"-array passed view looks this:
array( 'city' => array( (int) 0 => 'bitte eine stadt angeben' ), 'cart' => array( (int) 0 => 'bitte etwas eingeben' ), 'date' => array( (int) 0 => 'bitte das datum eingeben' ), 'time' => array( (int) 0 => 'bitte die zeit eingeben' ), 'income' => array( (int) 0 => 'bitte das trinkgeld in euro angeben' ), 'deliveryarea' => array( (int) 0 => 'postleitzahl existiert nicht!' ) )
the "deliveryarea" built in dynamically code:
//form errors formatieren für plz-validierung $this->post->set($this->request->data['post']); $this->post->validates(); $errors = $this->post->validationerrors + $this->zipcode->validationerrors; //in $errors die keys zipcode und deliveryarea anlegen und zipcode löschen if ($this->request->data['post']['b/s'] == 's' && !isset($errors['zipcode'])) { $errors['zipcode'] = $errors['zipcode']; }; if ($this->request->data['post']['b/s'] == 'b' && !isset($errors['deliveryarea'])) { $errors['deliveryarea'] = $errors['zipcode']; }; unset($errors['zipcode']); debug($errors); $this->set('validationerrors', $errors);
the problem fields showing red message except deliveryarea-one find strange ... in advance
i found solution. got validate within appmodel more consistent.
cake wants custom validation rules in class rule called. so, when call custom rule in class post, custom function has written down in class post, otherwise cake won´t find , validate false everytime.
the magic here import appmodel-class want use in class call validation-function. works following statement:
$zipcode = classregistry::init('class use - in case "zipcode"');
but if tables associated each other hasany or belongsto , stuff, custom functions works without that. important point mustn´t miss is, validation functions has introduced "public function xyz" otherwise cake won´t find them too.
Comments
Post a Comment