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.
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();
}
What about FormHelper::error() ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.