简体   繁体   中英

Unable to submit default value set in zf2

Am new to zf2 using zend form, Hydrator. I have managed to set the field element like

$this->add(array(
  'type' => 'text',
  'name' => 'name',
  'options' => array(
    'label' => 'Facility Name'
  )
));

$this->add(array(
  'type' => 'text',
  'name' => 'createdOn',
  'attributes' => array(
    'value' => date('d-m-Y'),         
  )
));

Displayed only Facility Name and not created On in the phtml

echo $this->formElementerrors($form->get('name'));
echo $this->formLabel($form->get('name'));
echo $this->formInput($form->get('name'));

When I submit the form, It keeps on giving me the error
Column 'createdOn' cannot be null

How can I set the default as current date to created on field and Submit with the form submit.

Value is filtered from the attributes array here . But to set default values in a form element there is a setValue method :

You can set it on element...

$element->setValue( 'some value' );

or you can use the form populateValues method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM