how to display error message in cakephp

Hi,

I have put validation on some fields in model file i.e joke.php

var $name = 'Joke';

public $validate = array('title' => array(

'rule' => 'notEmpty',

'message'=>'Please Enter Title'

),

'content' => array(

'rule' => 'notEmpty',

'message' => 'Please Enter content'

));

In view file (add.ctp), I used form to enter input value from user.

echo $this->Form->create('Joke');

echo $this->Form->input('title');

echo $this->Form->input('author');

echo $this->Form->input('content', array('rows' => '3'));

echo $this->Form->end('Add Joke');

It shows * as required field on Title & Content field. When user submit form without filling any value in these text fields then I want to display the error message which I defined in $validate array in model file.

Currently It is not showing any message. Can anyone help me to figure out how to display error message in view file.

Thank in advance

Baljeet Singh

Asked by baljeetsingh27, on 7/6/12

1 Answer

Your model/view seems to be ok.

Post your controller method add.

No need to say that errors are set after Joke->save() (or set()+validate())

Answered by Bootson 7/6/12

<< previous next >>

Your Answer

You can use Creole Wiki Syntax to format your text.

Rating

0

Viewed

761 times

Last Activity

on 7/6/12