Question

Due to the appearance of the website I'm working on, I've had to modify how radio fields appear on the screen in Cakephp. To do this, I create a radio input with the 'div' set to false, then I add my own version of a label and create the 'input radio' field div on top of this myself. However, this doesn't work with the built-in error messages added via the Cakephp validation. In other words, when a validation fails, the error class is not added to the fields div that I manually created. I'm wondering how Cakephp determines which div to add the error message to upon a validation failure. Can anyone explain this and/or point to where it happens in the code? Thanks!

Was it helpful?

Solution

If you're using the FormHelper, you can specify 'error' => false in the $options array when doing $form->input() or $form->radio(), or in the $form->create(); call if you're using that (this will turn off errors for ALL elements in the form though). That will turn off default error messages. You can then manually check for errors like so:

if ($form->error('ModelName.field_name')) {
    echo $form->error('ModelName.field_name');
}

You can add options while doing the specific error call - add div wrappers, class names, whatever you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top