In this article, we discussed how to do it:
http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html
I also give my example :
http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html
I also give my example :
public function buildForm(FormBuilderInterface $builder, array $options) { $factory=$builder->getFormFactory(); $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($factory){ // ... add a choice list of friends of the current application user $address = $event->getData(); $form = $event->getForm(); if ($address instanceof Address && $address->getWebSite()!=""){ $url=$address->getWebSite(); }else{ $url= 'http://www.'; } $form->add($factory->createNamed('webSite','url',$url,array( 'required'=> false, 'attr' => array('class' => 'defaultInvalid'), 'label' => 'form.address.label.webSite' )) ); }); }
评论
发表评论