I am trying to create a form with a date field where the user can select only the month and year (without the day of the month), but I cannot figure out how to do this.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'month',
'date',
array(
'label' => 'Month & year',
'input' => 'array',
'widget' => 'choice',
));
$builder->add('submit',
'submit');
}
The ideal result is two drop-down lists: a list of months (numerical representation) and a list of years (4 digits, last 5 years).
I think I can use 2 fields of choice type, but maybe there is a more elegant solution?
source
share