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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -