This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier 7ccfdb4016 feature #17644 Deprecate using Form::isValid() with an unsubmitted form (Ener-Getick)
This PR was merged into the 3.2-dev branch.

Discussion
----------

Deprecate using Form::isValid() with an unsubmitted form

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #7737
| License       | MIT
| Doc PR        | not yet

> I'm calling out for you to decide how to resolve the inconsistency between the Form::isValid() method and the ``valid`` variable available in the template:
>
> - ``isValid()`` returns ``false`` if a form was not submitted. This way it is possible to write concise controller code:
>
> ```php
> $form = $this->createForm(...);
> $form->handleRequest($request);
> if ($form->isValid()) {
>     // only executed if the form is submitted AND valid
> }
> ```
>
> - ``valid`` contains ``true`` if a form was not submitted. This way it is possible to rely on this variable for error styling of a form.
>
> ```twig
> <div{% if not form.vars.valid %} class="error"{% endif %}>
> ```
>
> We have two alternatives for resolving this problem:
>
> 1. Leave the inconsistency as is.
> 2. Make ``isValid()`` return ``true`` if a form was not submitted (consistent with ``valid``)
> 3. Revert to the 2.2 behavior of throwing an exception if ``isValid()`` is called on a non-submitted form (not consistent with ``valid``).
>
> Both 2. and 3. will require additional code in the controller:
>
> ```php
> $form = $this->createForm(...);
> $form->handleRequest($request);
> if ($form->isSubmitted() && $form->isValid()) {
>     // only executed if the form is submitted AND valid
> }
> ```
>
> What do you think?

This PR implements the option 3 as it was the most chosen in #7737

Commits
-------

2c3a7cc Deprecate using Form::isValid() with an unsubmitted form
2016-06-17 19:33:12 +02:00
.composer Drop hirak/prestissimo 2016-05-12 07:44:15 -05:00
.github Add 3.1 to PR template branch row, remove 2.3 2016-06-01 21:19:49 +02:00
src/Symfony Deprecate using Form::isValid() with an unsubmitted form 2016-06-17 18:23:40 +02:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore Add appveyor.yml for C.I. on Windows 2015-08-25 23:41:37 +02:00
.php_cs use nowdoc instead of heredoc 2015-12-21 17:05:00 +01:00
.travis.php Merge branch '3.0' 2016-05-13 13:06:41 -05:00
.travis.yml Merge branch '3.1' 2016-06-14 13:18:32 +02:00
appveyor.yml [Cache] Optimize & wire PhpFilesAdapter 2016-05-31 18:28:43 +02:00
CHANGELOG-3.0.md Merge branch '2.8' into 3.0 2016-06-14 13:04:19 +02:00
CHANGELOG-3.1.md updated CHANGELOG for 3.1.1 2016-06-15 07:58:54 +02:00
composer.json updated version to 3.2 2016-05-13 13:13:23 -05:00
CONTRIBUTING.md Update contributing docs 2016-02-24 15:36:06 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.7.14 2016-06-06 17:23:21 +02:00
LICENSE Update copyright year 2016-01-01 23:53:47 -03:00
phpunit update tests to use the new error assertion helper 2016-06-16 10:10:24 +02:00
phpunit.xml.dist Merge branch '3.0' 2016-03-16 18:16:29 +01:00
README.md Merge branch '2.8' 2015-06-04 22:30:47 +02:00
UPGRADE-3.0.md Merge branch '3.0' into 3.1 2016-06-03 13:12:53 +02:00
UPGRADE-3.1.md [YAML] fixed "dump" signature in upgrade file 2016-05-18 11:23:21 +02:00
UPGRADE-3.2.md Deprecate using Form::isValid() with an unsubmitted form 2016-06-17 18:23:40 +02:00
UPGRADE-4.0.md Deprecate using Form::isValid() with an unsubmitted form 2016-06-17 18:23:40 +02:00

README

What is Symfony?

Symfony is a PHP full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easy to maintain websites with PHP.

Symfony can be used to develop all kind of websites, from your personal blog to high traffic ones like Dailymotion or Yahoo! Answers.

Installation

The best way to install Symfony is to use the official Symfony Installer. It allows you to start a new project based on the version you want.

Documentation

The "Quick Tour" tutorial gives you a first feeling of the framework. If, like us, you think that Symfony can help speed up your development and take the quality of your work to the next level, read the official Symfony documentation.

Contributing

Symfony is an open source, community-driven project. If you'd like to contribute, please read the Contributing Code part of the documentation. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section and use Pull Request Template.

Running Symfony Tests

Information on how to run the Symfony test suite can be found in the Running Symfony Tests section.