CakePHP 2.3.1 Deactivates Form Validation in Certain Views

The cookbook provides for version 2.3 the ability to deactivate force validation for forms. Or at least I understood it this way: Quote: from http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

"New in version 2.3.

Starting from 2.3, the required HTML5 attribute will also be added to the input based on the rules of validation. You can explicitly set the required key in to override it for the field. To skip browser validation trigger for the whole form, you can set the option 'formnovalidate' => true for the input button that you create using FormHelper :: submit () or set 'novalidate' => true in the parameters for FormHelper :: create ( ). "

In my case, I have a search for this model, and, of course, the user does not need to fill in all the required fields, for example, to add a data set. Therefore, I want to deactivate validation for my search form.

I have tried all three options and can’t see the results: nevertheless, the required fields for creation are mandatory in my search form.

Those attempts that I made:

first try:

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

second attempt:

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

third attempt:

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

variations:

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

What did I misunderstand? By the way: I deactivated caching, so this is not a problem.

Of course, I could use the old workaround for this check, but when 2.3 offers this option, I would love to use it.

Calamity Jane

+5
source share
4 answers

, , , , :

:

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

, , . , , , . , , , , 99 , .

, , , , HTML5 . , , ?

+7

. , . , -

echo $this->Form->create('PartnerSearch');

:

$this->request->data["PartnerSearch"]["field"] 

:

$this->request->data["Partner"]["field"]
+1

For me, to skip the browser check, yes, it array('novalidate' => true)works.

<?php echo $this->Form->create('MyModelName', array('novalidate' => true)); ?>

To keep the label in bold and an asterisk,

<?php echo $this->Form->input('myinput', array('required' => false));
0
source

In my case, I used a button to submit the form. This allowed me more flexibility. In this case, I used the "formnovalidate" property in the options array for the button. The form will look something like this:

<?php
echo $this->Form->create('yourCtrllerName',array('action'=>'actionInYourCtrller'));
echo $this->Form->input('your_field_pass',array('label'=>'pass','type'=>'password'));
....  other Form fields .....
echo $this->Form->button('Button Caption',
                          array('type'=>'submit',
                                'name'=>'keyInsideTheDataArrayForButtonData',
                                'formnovalidate' => true,
                                'value'=>'valueOfTheAboveKeyInTheDataArray',
                                'style'=>'<style you want to apply to button>',
                                ... other options if needed...
                                )
                         );
echo $this->Form->end();
0
source

All Articles