Bit of a moot point for me... was using Username as an example, but its
actually not a username, so the only validation rule I have on the field is
isUnique...

also not using localization...
having said that, would be nice if the model validation rules supported
returning the input string in the message....


On Thu, Dec 30, 2010 at 8:19 AM, john lyles <confidentia...@gmail.com>wrote:

> >> But wouldn't this error message be displayed when *any* validation error
> with the username field occurs? What if I also have validation checks for
> whether it's >>empty, whether it's too short, whether it includes invalid
> characters? Anyway, wouldn't I want to specify validation errors in the
> controller, not in the view?
>
> Ryan, good point about the error message being displayed for any
> error. I hadn't thought that far ahead. The solution would be to
> specify the keyname of the validation rule. The example in the manual
> not fixed for this situation is: $this->Form->input('Model.field',
> array('error' => array('tooShort' => __('This is not long enough',
> true) )));
>
> As for the second point about handling this in the controller. It's
> the manual itself that says this should be handled with FormHelper.
> From this page here: http://book.cakephp.org/view/1143/Data-Validation
> , it says: "For more information about how to handle the displaying of
> validation errors, check out the section covering FormHelper."
>
>
> On Dec 29, 4:40 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:
> > On Dec 29, 2010, at 11:24, john lyles wrote:
> >
> > > If your form looked something like this you would get the result you
> > > are looking for:
> > > echo $this->Form->input('username', array('error' =>
> $this->data['User']['username'] . ' is taken'));
> >
> > And of course if you wanted that to be localizable:
> >
> > echo $this->Form->input('username', array('error' => sprintf(__('%s is
> taken', true), $this->data['User']['username'])));
> >
> > But wouldn't this error message be displayed when *any* validation error
> with the username field occurs? What if I also have validation checks for
> whether it's empty, whether it's too short, whether it includes invalid
> characters? Anyway, wouldn't I want to specify validation errors in the
> controller, not in the view?
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to