CakePHP 2.3.1 deactivate form validation in certain views

Calamity Jane picture Calamity Jane · Mar 19, 2013 · Viewed 11.1k times · Source

The Cookbook introduces for version 2.3 the possibility to deactivate the forced valiadation for forms. Or at least I understood it like that: Quote: from http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

" New in version 2.3.

Since 2.3 the HTML5 required attribute will also be added to the input based on validation rules. You can explicitly set required key in options array to override it for a field. To skip browser validation triggering for the whole form you can set option 'formnovalidate' => true for the input button you generate using FormHelper::submit() or set 'novalidate' => true in options for FormHelper::create()."

In my case I have a search from for this model and of course the user does not need to fill in all mandatory fields like for adding a dataset. So I want to deactivate the validation for my search form.

I tried all three variations and see no results: Still the mandatory fields for create are mandatory in my search form.

Those attempts I made:

first try:

echo $this->Form->create('Partner', array('action' => 'search', 'novalidate' => true));

second try:

echo $this->Form->input('name', 
array('required' => false, 'value' => $this->Session->read('Searchparameter.name'))
);

third try:

 $this->Form->submit('Submit', array('formnovalidate' => true));
    echo $this->Form->end();

variation:

echo $this->Form->end(__('Submit'), array('formnovalidate' => true));

What did I understand wrong? btw: I did deactivate caching, so that should not be the problem.

Of course I could still use the old workaround for this validation, but when 2.3 is offering this option, I would gladly use it.

Calamity Jane

Answer

Calamity Jane picture Calamity Jane · Mar 20, 2013

So I guess I found the problem and at least got one varation working:

What I am using now is:

echo $this->Form->create('Partner', array('action' => 'search', 'novalidate' => true));

I guess what I expected was that the fields wouldn't be marked with the fat label and the asterisk. Those are still there, but regardless you don't have to fill them in anymore. And the times I tested with really submittig the form I guess I had one of the 99 varations, which was really wrong.

If that makes me happy is mine to decide, but obviously I can switch off the HTML5 validation by that. If I would want to have the labels not bold & asterisk, is there an option, too?

Calamity Jane