SfWidgetFormChoice* with spicy empty values

To pass empty values to the widgets based on choices is really simple with symfony.

For example, the sfWidgetFormDoctrineChoice accepts a with_empty option, which can be a boolean or a string:

1
2
3
<?php

new sfWidgetFormDoctrineChoice(array('model' => 'ModelName', 'add_empty' => ...));

which renders the empty option according to the following rules:

1
2
3
4
given true:
  null => ''
given a string:
  null => 'string' 

The other widget I was working on, sfWidgetFormI18nDate, accepts an array to configure empty options:

1
2
3
<?php

new sfWidgetFormI18nDate(array('culture' => 'en', 'empty_values' => $empty_values));

with the following format:

1
2
3
4
Array
  day:   Day
  month: Month
  year:  Year

and the rendered form is something like this:


In the mood for some more reading?

...or check the archives.