Reputation: 2570
I have a view where I used FormHelper methods ($this->Form->input
, etc.) to create a form (post), but this form is not tied to any model. It's a dumb form.
For example, some fields are date fields. My controller will do some validation on these fields, but if there is a problem, how would I display the error message right below the field that had a validation error? With forms tied to models, CakePHP will automagically add a div to the relevant field to display the validation error message. Is there something similar for dumb forms?
Thank you for the assistance.
Upvotes: 0
Views: 2573
Reputation: 8100
Use a model which isn't associated with a db table. Rest will be same as using a regular db backed model. Eg:
// Model
class Dummy extends Model {
public $useTable = false;
public $validate = array('somefield' => 'notEmpty');
}
// View
echo $this->Form->create('Dummy');
echo $this->Form->input('somefield');
......
// Controller
public some_action() {
//if post request
$this->Dummy->set($this->request->data);
$this->Dummy->validates();
}
Upvotes: 2
Reputation: 3889
What about FormHelper::error() ?
http://api.cakephp.org/1.3/class-FormHelper.html#_error
Upvotes: 0