Creating a now button in a symfony form, for a datetime field

I’m building a project management webapp in Symfony. It has a Project class. That Project class has status flags like created, offer_sent, offer_confirmed, completed, frozen etc. They are modeled as datetime fields in the database, being null when not yet known (as in completed is null while the project is not yet completed) and are supposed to get set to the date they happened.

For now, the project controller is mostly a doctrine generated CRUD controller, the forms are thus autogenerated as follows:

public function buildForm(FormBuilderInterface $builder, array $options)

Now, this generates a form that has selects for the day, the month, the year, the hour and the minute, which is of course rather tedious to use.

Now. I’d like to know how I can customise the form in a way such that I get a) just a button “now” which sets the datetime to the current time and date or b) the same date selector (or the html5 version with single_text) and additionally a “now” button next to it.

I have read about creating custom field types here, but I haven’t been able to wrap my head around it far enough to create a form like the one I’d like.

Any help would be greatly appreciated, thank you.

Source: forms

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.