dongliufa6380 2010-09-02 11:29
浏览 42
已采纳

CakePHP表单验证错误放置

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!

  • 写回答

1条回答 默认 最新

  • douyan1970 2010-09-02 12:37
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部