简体   繁体   中英

Cakephp 1.3 - How is the validation error message added to the div of the field?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM