Skip to content

[#2963] Disabling validation corectly #3346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 26, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,10 @@ Disabling Validation
.. versionadded:: 2.3
The ability to set ``validation_groups`` to false was added in Symfony 2.3,
although setting it to an empty array achieved the same result in previous
versions.
versions. Please note that empty array doesn't work anymore.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we should remove that sentence from this note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what would be the the correct form of that sentences?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just remove everything after the comma on lin 480 and replace the comma by a dot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Sometimes it is useful to suppress the validation of a form altogether. For
these cases, you can skip the call to :method:`Symfony\\Component\\Form\\FormInterface::isValid`
in your controller. If this is not possible, you can alternatively set the
``validation_groups`` option to ``false`` or an empty array::
these cases you can set the ``validation_groups`` option to ``false``::

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

Expand All @@ -497,9 +495,8 @@ in your controller. If this is not possible, you can alternatively set the

Note that when you do that, the form will still run basic integrity checks,
for example whether an uploaded file was too large or whether non-existing
fields were submitted. If you want to suppress validation completely, remove
the :method:`Symfony\\Component\\Form\\FormInterface::isValid` call from your
controller.
fields were submitted. If you want to surppress validation you can use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo surppress -> suppress

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I prefer to add a comma before 'you'

:ref:`POST_SUBMIT event <cookbook-dynamic-form-modification-supressing-form-validation>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[..] you can use the POST_SUBMIT event


.. index::
single: Forms; Validation groups based on submitted data
Expand Down
30 changes: 30 additions & 0 deletions cookbook/form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,33 @@ after the sport is selected. This should be handled by making an AJAX call
back to your application. In that controller, you can submit your form, but
instead of processing it, simply use the submitted form to render the updated
fields. The response from the AJAX call can then be used to update the view.

.. _cookbook-dynamic-form-modification-supressing-form-validation:

Supressing Form Validation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo supressing -> suppressing

---------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have one dash to much here


One way you can use ``POST_SUBMIT`` event is to completely supress
form validation. The reason for that is even if you set ``group_validation``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To suppress form validation, you can use the POST_SUBMIT event.

to ``false`` there still some integrity check are run, for example whether
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] there are still some integrity checks executed, for example [...]

an uploaded file was too large or whether non-existing fields were submitted.

If you want to suppress even that, you should use ``POST_SUBMIT`` event to prevent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a bit rendundant with the start of the previous paragraph

:class:`Symfony\\Component\\Form\\Extension\\Validator\\EventListener\\ValidationListener`
invocation::

use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvents;

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(FormEvents::POST_SUBMIT, function($event) {
$event->stopPropagation();
}, /* priority higher than ValidationListener */ 200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just set this to a high value, e.g. 900 to be sure it'll always work?


// ...
}

Note that that by doing that you can disable something more than form validation,
because ``POST_SUBMIT`` event can be used for something else.
You also have to know what would be the right priority for disabling POST_SUBMIT events.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add this is a caution block?

.. caution::

    By doing this, you can disable something more than just form validation,
    because the ``POST_SUBMIT`` event can be used for something else.

That last sentence seems to be a bit useless for me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jus -> just