-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Labels
RFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)Validator
Description
As has been brought up multiple times (e.g. #11943, #11083, #7412), it's confusing that the string validation constraints ignore empty strings. Should we change this behavior with Symfony 3.0?
- Remove
Blank
/NotBlank
- Remove
if ('' === $value) { return; }
from all constraint validators
A consequence would be that for manually validating form submissions, one will have to pre-process the $_POST
array before the validation and convert empty strings to null
manually:
$formValues = array_replace_recursive($defaultValues, $_POST['form']);
array_walk_recursive($formValues, function (&$value) { if ('' === $value) { $value = null; } });
$validator->validate($formValues, new Collection(array(
'name' => array(
new NotNull(),
new Length(array('min' => 3)),
),
// ...
));
See also the related discussion about separating the type validation from constraint validators in #10221.
localheinz
Metadata
Metadata
Assignees
Labels
RFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)Validator