mentalic
mentalic

Reputation: 996

Invalidate field from controller

I have an action/view that is going to be used for reporting purposes, no saving of data involved.

I want some form elements to be valid/invalid and if invalid, some errors to be shown.

What is the most CakePHPish way for showing errors in form fields that are not based on a model?

Upvotes: 0

Views: 417

Answers (2)

kaklon
kaklon

Reputation: 2432

You can validate your data without saving, within the controller like so:

$this->ModelName->validates()

For more information, please refer here: Validating Data from the Controller

Upvotes: 1

Oldskool
Oldskool

Reputation: 34857

Even if you're not getting or saving your data from a database table, you still need a model for validation rules, that's the proper MVC way. You can set

var $useTable = false;

In your model if you're not planning on saving/reading anything. You can then use your model to just set your validation rules and messages.

Upvotes: 1

Related Questions