single: Forms; Fields; date
A field that allows the user to modify date information via a variety of different HTML elements.
The underlying data used for this field type can be a DateTime
object, a string, a timestamp or an array. As long as the input option is set correctly, the field will take care of all of the details.
The field can be rendered as a single text box, three text boxes (month, day, and year) or three select boxes (see the widget option).
Underlying Data Type | can be DateTime , string, timestamp, or array (see the input option) |
Rendered as | single text box or three select fields |
Options | |
Overridden Options | |
Inherited options | |
Parent type | field (if text), form otherwise |
Class | Symfony\\Component\\Form\\Extension\\Core\\Type\\DateType |
This field type is highly configurable, but easy to use. The most important options are input
and widget
.
Suppose that you have a publishedAt
field whose underlying date is a DateTime
object. The following configures the date
type for that field as three different choice fields:
$builder->add('publishedAt', 'date', array(
'input' => 'datetime',
'widget' => 'choice',
));
The input
option must be changed to match the type of the underlying date data. For example, if the publishedAt
field's data were a unix timestamp, you'd need to set input
to timestamp
:
$builder->add('publishedAt', 'date', array(
'input' => 'timestamp',
'widget' => 'choice',
));
The field also supports an array
and string
as valid input
option values.
type: string
or array
If your widget option is set to choice
, then this field will be represented as a series of select
boxes. The empty_value
option can be used to add a "blank" entry to the top of each select box:
$builder->add('dueDate', 'date', array(
'empty_value' => '',
));
Alternatively, you can specify a string to be displayed for the "blank" value:
$builder->add('dueDate', 'date', array(
'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day')
));
default: false
The DateTime
classes are treated as immutable objects.
default: false
These options inherit from the form </reference/forms/types/form>
type:
Variable | Type | Usage |
---|---|---|
widget | mixed |
The value of the widget option. |
type | string |
Only present when widget is single_text and HTML5 is activated, contains the input type to use (datetime , date or time ). |
date_pattern | string |
A string with the date format to use. |