Galuk
Galuk

Reputation: 15

zend framework 2 change date format in form

I am trying to change date format in ZF2 application. I have tried this :

         $this->add(array(
         'type' => 'Zend\Form\Element\Date',
         'name' => 'date_of_entry',
         'options' => array(
                 'label' => 'Datum unosa',
                 'format' => 'd-m-Y'
         ),
         'attributes' => array(
                 'class' => 'my_input',
                 'min' => '01-01-1970',
                 'step' => '1', 
         )
     ));
    $this->get('date_of_entry')->setFormat('d-m-Y'); 

In view I am getting mm\dd\yyyy format, what is wrong?

Upvotes: 0

Views: 2710

Answers (1)

Mubo
Mubo

Reputation: 1070

You can’t set the format within the array – it has to be via a setFormat() call.

I think you need to remove this 'format' => 'd-m-Y'

$this->add(array(
         'type' => 'ZendFormElementDateTime',
         'name' => 'date_of_entry',
         'options' => array(
                 'label' => 'Datum unosa',
              ),
         'attributes' => array(
                 'class' => 'my_input',
                 'min' => '01-01-1970',
                 'step' => '1', 
        )
    )
);
$this->get('date_of_entry')->setFormat('d-m-Y');

Hope this will work for you.

Upvotes: 2

Related Questions