Harsha M V
Harsha M V

Reputation: 54949

Cakephp 2.1 Form Error

I have just started using cakePHP 2.1. After submiting a form. If there is a validation error how to check the params whether there is an error ?

Before we used to do something like

$this->data['params'];

Upvotes: 0

Views: 326

Answers (2)

Saanch
Saanch

Reputation: 1844

Andrew Perk has posted some excellent videos in Youtube for CakePHP. You can watch one of those explains how can do an AJAX validation with CakePHP and jQuery.

Please watch it Cakephp Ajax Tutorial - Using Cakephp's Js Helper and jQuery
It may be helpful for you.

Upvotes: 1

Ehtesham
Ehtesham

Reputation: 2985

For example if you are saving the data in Form submit and you have validations defined on that Model, the data will be saved only when the call to Model->save() returns true. In that case most probably you have validations error. The way you can specifically check is to check Model's validationErrors proprty.

In your controller

    if(!$this->Model->save($data)) {
         if(!empty($this->Model->validationErrors)) {
             //save failed due to validation errors
             debug($this->Model->validationErrors);
         }
    }

Upvotes: 1

Related Questions