8000 bug #12072 Remove strict true === $user['showEmail'] on preSubmit (jb… · symfony/symfony-docs@a728c69 · GitHub
[go: up one dir, main page]

Skip to content

Commit a728c69

Browse files
committed
bug #12072 Remove strict true === $user['showEmail'] on preSubmit (jbdelhommeau)
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #12072). Discussion ---------- Remove strict true === $user['showEmail'] on preSubmit <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> On the pre submit example. Strict condition will be used. `true === $user['showEmail']`. In pre submit value of data are not normalized. Strict operator `true === $user['showEmail']` is wrong. If we want used strict operator we can use: `'1' === $user['showEmail']`. but in case of checkbox is not checked the key `showEmail` is not set. I prefere use this condition: `isset($user['showEmail']) && $user['showEmail']` or maybe `false === empty($user['showEmail'])` ? Commits ------- 122ccaa Remove strict true === $user['showEmail'] on preSubmit
2 parents eebc2e4 + 122ccaa commit a728c69

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

form/events.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Creating and binding an event listener to the form::
287287
// checks whether the user has chosen to display their email or not.
288288
// If the data was submitted previously, the additional value that is
289289
// included in the request variables needs to be removed.
290-
if (true === $user['showEmail']) {
290+
if (isset($user['showEmail']) && $user['showEmail']) {
291291
$form->add('email', EmailType::class);
292292
} else {
293293
unset($user['email']);
@@ -383,7 +383,7 @@ Consider the following example of a form event subscriber::
383383
// checks whether the user has chosen to display their email or not.
384384
// If the data was submitted previously, the additional value that
385385
// is included in the request variables needs to be removed.
386-
if (true === $user['showEmail']) {
386+
if (isset($user['showEmail']) && $user['showEmail']) {
387387
$form->add('email', EmailType::class);
388388
} else {
389389
unset($user['email']);

0 commit comments

Comments
 (0)
0