VishwaKumar
VishwaKumar

Reputation: 3433

Symfony2: How do i validate start and end dates of an entity?

I am using start and end dates over multiple forms, but these properties are in a single entity. Now is there a way to compare the dates and display appropriate error messages inside each form.

Could anyone guide me for a best way to implement this.

Thanks!

Upvotes: 1

Views: 3688

Answers (1)

AlterPHP
AlterPHP

Reputation: 12717

The best way would be, on my opinion, to create your own form field with these 2 dates and its own validation rules. But this requires some strong symfony2 knowledges. Here are some useful links about custom form field types creation :

A quick and dirty way is to add a callback validation for each form implementing start and end date. More infos over here : http://symfony.com/doc/current/reference/constraints/Callback.html

Upvotes: 1

Related Questions