I just recently ran into a problem, where my Symfony2 app renders form with invalid date choice input. Specifically, it renders the "month" select with numbers inside, instead of month names.
The definition of the form type goes like this:
$builder
->add('title')
->add('shortcut')
->add('description')
->add('category')
->add('release_date', 'date', array(
'input' => 'datetime',
'widget' => 'choice'
));
This definition then (by using form_widget in Twig) renders the following for month select:
<select id="nucleo_gamesbundle_gametype_release_date_month" name="nucleo_gamesbundle_gametype[release_date][month]" required="required">
<option value="1">1326585600</option>
<option value="2">1329264000</option>
<option value="3">1331769600</option>
<option value="4">1334448000</option>
<option value="5">1337040000</option>
<option value="6">1339718400</option>
<option value="7">1342310400</option>
<option value="8">1344988800</option>
<option value="9">1347667200</option>
<option value="10">1350259200</option>
<option value="11">1352937600</option>
<option value="12">1355529600</option>
</select>
Does anyone know, how to force Symfony to render option texts as month names (eg. January, February, etc.)? Thank you very much.
EDIT: Twig template (the form part) looks like this:
<form action="{{ path('game_admin_update', {'id' : entity.id}) }}" method="post" class="form" {{ form_enctype(edit_form) }}>
<fieldset>
<div class="widget">
<div class="title"><img src="{{ asset('admin/images/icons/dark/list.png') }}" alt="" class="titleIcon" /><h6>Základní informace</h6></div>
<div class="formRow">
{{ form_label(edit_form.title, 'form.game.title'|trans({},'admin')) }}
<div class="formRight">{{ form_widget(edit_form.title) }}</div>
<div class="clear"></div>
</div>
<div class="formRow">
{{ form_label(edit_form.shortcut, 'form.game.shortcut'|trans({},'admin')) }}
<div class="formRight">{{ form_widget(edit_form.shortcut) }}</div>
<div class="clear"></div>
</div>
<div class="formRow">
{{ form_label(edit_form.description, 'form.game.description'|trans({},'admin')) }}
<div class="formRight">{{ form_widget(edit_form.description, { 'attr': {'class': 'richEditor'} }) }}</div>
<div class="clear"></div>
</div>
<div class="formRow">
{{ form_label(edit_form.release_date, 'form.game.release_date'|trans({},'admin')) }}
<div class="formRight">{{ form_widget(edit_form.release_date) }}</div>
<div class="clear"></div>
</div>
{{ form_rest(edit_form) }}
<div class="formSubmit"><input type="submit" value="{{ 'form.game.submit.edit'|trans({},'admin') }}" class="greenB" /></div>
<div class="clear"></div>
</div>
</fieldset>
So nothing special there
Of course, you can provide a format option to transform the datetime into the format of your choice:
This will print a select box for the year, e.g.
2012
, one for the month with the long month names, and one for the day, e.g.21
. Take a look here for more formats.