Skip to content

Commit

Permalink
minor #1443 Fix comment stating isSubmitted is optional (smnandre)
Browse files Browse the repository at this point in the history
This PR was merged into the main branch.

Discussion
----------

Fix comment stating isSubmitted is optional

The isSubmitted() _must_ be called before

[src/Symfony/Component/Form/Form.php](https://github.com/symfony/symfony/blob/6637b78a4fcba7cef818f2a022e096d503690ac5/src/Symfony/Component/Form/Form.php#L646-L657)
```php

    public function isValid(): bool
    {
        if (!$this->submitted) {
            throw new LogicException('Cannot check if an unsubmitted form is valid. Call Form::isSubmitted() and ensure that it\'s true before calling Form::isValid().');
        }

        if ($this->isDisabled()) {
            return true;
        }

        return 0 === \count($this->getErrors(true));
    }
 ```

Commits
-------

6da03aa Fix comment stating isSubmitted is optional
  • Loading branch information
javiereguiluz committed Oct 23, 2023
2 parents 578246c + 6da03aa commit 23ff699
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Controller/Admin/BlogController.php
Expand Up @@ -86,9 +86,8 @@ public function new(

$form->handleRequest($request);

// the isSubmitted() method is completely optional because the other
// isValid() method already checks whether the form is submitted.
// However, we explicitly add it to improve code readability.
// The isSubmitted() call is mandatory because the isValid() method
// throws an exception if the form has not been submitted.
// See https://symfony.com/doc/current/forms.html#processing-forms
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($post);
Expand Down

0 comments on commit 23ff699

Please sign in to comment.