Wizard
Wizard

Reputation: 11285

CakePHP 2.x disable defined rule in model for special field

In form I'm using model. In model I have defined validation rules. How I can disable specific rule in form without removing this in model.

I searching for something like that- for solution to set validate false for specific field example:

                    <?php echo $this->Form->input(
                        'phone',
                        array('type'       => 'text',
                              'div'        => array('class' => "input-wrap"),
                              'label'      => false,
                              'validate'   => false,
                        )
                    ) ?>

Upvotes: 1

Views: 899

Answers (2)

pankaj bhaliya
pankaj bhaliya

Reputation: 1

You can try this way also in the controller

unset($this->ExampleModel->validate['emailaddress']['unique']);

Upvotes: 0

drmonkeyninja
drmonkeyninja

Reputation: 8540

You want to alter the validation rules in your controller before you save the form rather than within the View.

For example, if you wanted to remove all validation rules for the phone field:-

$this->ExampleModel->validator()->remove('phone');

If you just want to remove a specific rule from the field you can do that too. For example, if you have a rule named required for the phone field:-

$this->ExampleModel->validator()->remove('phone', 'required');

You can read up on this in the official docs.

Upvotes: 3

Related Questions