Skip to content

[Form] Fixed edge case where empty data may not be a string and throws TransformationFailedException #13598

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

Closed
Changes from all commits
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: 11 additions & 0 deletions src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,17 @@ public function submit($submittedData, $clearMissing = true)
$emptyData = $emptyData($this, $viewData);
}

// Treat false as NULL to support binding false to checkboxes.
// Don't convert NULL to a string here in order to determine later
// whether an empty value has been submitted or whether no value has
// been submitted at all. This is important for processing checkboxes
// and radio buttons with empty values.
if (false === $emptyData) {
$emptyData = null;
} elseif (is_scalar($emptyData)) {
$emptyData = (string) $emptyData;
}

$viewData = $emptyData;
}

Expand Down