php - How do you validate Symfony BirthdayType fields?
Get the solution ↓↓↓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".
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.