开发者

CakePHP Form Validation Error Placement

开发者 https://www.devze.com 2023-01-14 01:00 出处:网络
Is there any way to change the placement of form validation messages in CakePHP? For instance, I have the following:

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 adv开发者_如何学编程ance 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

0

精彩评论

暂无评论...
验证码 换一张
取 消