php - FormType default input value in same form -
i have entity named task , build symfony tasktype.php form. aim set enddate datetime field default input of startdate datime field (which required).
i tried this, doesn't work.
$builder->add('name'); $builder->add('startdate', 'datetime'); $builder->add('enddate', 'datetime', array( 'empty_value' => array('year' => 'year', 'month' => 'month', 'day' => 'day'), 'required' => false, 'data' => isset($options['data']) ? $options['data']->getenddate() : $options['data']->getstartdate(), ));
exception:
an exception occurred while executing 'insert task (name, startdate, enddate) values (?, ?, ?)' params {"1":"test","2":"2013-03-30 00:00:00","3":null}:
sqlstate[23000]: integrity constraint violation: 1048 column 'enddate' cannot null 500 internal server error - dbalexception 1 linked exception:
pdoexception »
yes, of course doesn't work. recommend read how form works, if have no time can read "cheatsheet" - http://blog.stfalcon.com/wp-content/uploads/2012/01/how_symfony2_forms_works.pdf.
you can set value after data set. example, try:
$form->bindrequest($request); // can data , set $form->get('enddate')->setdata($form->get('startdate')->getdata());
hope, helps.
Comments
Post a Comment