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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -