Displaying Customized Error Message CakePHP 1.2

When we provide the error message in a particular model, then after validating, CakePHP automatically displays that error message below the respective input control, by creating their own div and error message class. But we can also show the error message in our own style using error function of form helper ($form->error()).

Suppose there is an input box for user name in add_user.ctp:


echo $form->input('User.user_name', array('type'=>'text', 'label'=>false, 'div'=>false, 'error' => false));

When we set ‘error’ parameter to false, then cake will not automatically generate the error message div.

Now to show the error –


echo $form->error('User.user_name', null, array('class'=>'error-message'));

Where we call $form->error(), the error message will be displayed in that place.

Leave a comment

Your email address will not be published. Required fields are marked *