Zend Framework 2 DateSelect / Month Select formatting

With the recently released version of Zend Framework 2 , two new form elements have been added ; DateSelectand MonthSelect. I want to use the first, which adds three choices; day, month and year. However, I have a problem with formatting the output as I want - and there is no documentation for this!

I add a form element to my form like this (taken from on this page ):

$this->add(array(
    'type'    => 'Zend\Form\Element\DateSelect',
    'name'    => 'birthDate',
    'options' => array(
        'label'               => 'Date',
        'create_empty_option' => true,
        'day_attributes'      => array(
            'data-placeholder' => 'Day',
            'style'            => 'width: 20%',
        ),
        'month_attributes'    => array(
            'data-placeholder' => 'Month',
            'style'            => 'width: 20%',
        ),
        'year_attributes'     => array(
            'data-placeholder' => 'Year',
            'style'            => 'width: 20%',
        )
    )
));

To output, I do this:

echo $this->formDateSelect($form->get('birthDate'));

The fact is, I don’t know how to control the way formatting selections. For example, they are currently displayed in this form: [month] [day], [year]. I want to change two things; firstly, I want to switch the day and month, and secondly, I want to get rid of the comma.

IntlDateFormatter . , __invoke() [ ], :

echo $this->formDateSelect($form->get('birthDate'), IntlDateFormatter::SHORT);

, .

, , formSelect , . ; .

- , , ? , ?

+5
3

ViewHelper - $this->formDateSelect($element, $intlFormat, $locale).

, int ViewHelpers __invoke(). getLocale() ViewHelper, , translator , locale ViewHelper, ;)

, Bakura

+2

, - Select DOM ... ?

, :

"render_delimiters": false

, ,

+2

As Sam says, you can just update the locale settings in php.ini

For example, I have this in my php.ini

intl.default_locale = en_Gb

This formats the DateSelect element in the Day / Month / Year format, which is required for my UK projects.

0
source

All Articles