symfony - Remove field in update form Entity (Symfony2) -
i'm working symfony2, , have form number of fields, 1 of them called video. possible remove field in update form not in insert form?
(form) youtubeposttype.php:
$builder->add('titulovideo') ->add('descripcionvideo') ->add('tagsvideo') ->add('video', 'file', array('required' => false));
thank in advanced.
if controller defining form fields directly, can add if statement after define main fields, check if it's not update before adding video
field, e.g.
$builder->add('titulovideo') ->add('descripcionvideo') ->add('tagsvideo'); if($mymethod != 'update') { $builder->add('video', 'file', array('required' => false)); }
but assuming have defined custom form collection of fields field defined in form builder object , loading collection in controller, in case remove it:
$form = $this->createform(new mycollectiontype(), $entity); if($mymethod == 'update') { $form->remove('video'); }
if it's field associated entity, entity first , remove there:
$form->get('myentityname')->remove('myfieldname')
note: if manually creating form template, , try hide in template (e.g. set inside if statement), won't work:
{% if $mymethod == 'update' %} {{ form_row(form.video) }} {% endif %}
the form renderer add end of form anyway (in experience), won't work.
Comments
Post a Comment