简体   繁体   中英

CakePHP Form Validation Error Placement

Is there any way to change the placement of form validation messages in CakePHP? For instance, I have the following:

In the view:

echo $form->input('fname', array('before' => '<li>', 'label' => 'First Name', 'after' => '</li>'));

In the controller:

'fname' => array('rule' => 'notEmpty', 'message' => 'Please enter your first name.'),

This displays the error message next to the field, but is this enclosed in a DIV or is there a way to enclose the message in a DIV in order to improve its look/positioning?

I could not find anything about this in the documentation.

Thank you in advance for any help!

Well, there are a few basic things you can do by using the error option in $form->input. wrap will let you wrap the error in a different element type, and class lets you specify a class.

$form->input('fname', array('before' => '<li>', 'label' => 'First Name', 'after' => '</li>', 'error' => array('wrap' => 'div', 'class' => 'my-error-class')));

There's a bit more info about it in the Cookbook.

http://book.cakephp.org/view/198/options-error

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