php - How do you validate Symfony BirthdayType fields? ← (PHP, Symfony, HTML)

I'm trying to validate a BirthdayType field. The form field is like this:

->add('birthday', BirthdayType::class, [
    'placeholder' => [
        'year' => 'select-year',
        'month' => 'select-month',
        'day' => 'select-day',
    ]
])

And the field validation is defined like this:

/**
 * @Assert\Date(
 *      message = "Field should be a date"
 * )
 *
 * @Assert\NotBlank(
 *      groups = {"Signup"},
 *      message = "Field must not be blank"
 * )
 *
 * @ORM\Column(type="string", name="birthday")
 */
 private $birthday;

On form submit, this is what's posted to the controller:

[form] => Array
    (
        [birthday] => Array
            (
                [year] => 
                [month] => 
                [day] => 
            )
    ...
    )

When the validation runs, all other form fields are validated properly except for this one. Am I missing something obvious that's preventing this field from being validated as a Date/Birthday?

I've tried adding these to the form field but they appear to have had no effect:

'error_bubbling' => true//false,
'compound' => false//true

Answer



Solution:

The BirthdayType return a Datetime Symfony Doc

In your @ORM\Column annotation try to set type="date".

Source