I need to set my form's target
attribute in Symfony2
using FormBuilder
.
I tried this:
$fb = $this->createFormBuilder();
$fb->setAttribute('target', '_top');
but it doesnt work!
Why?
How can I do this?
Try to pass it as a constructor argument (among options) as such:
$fb = $this->createFormBuilder(null, array('attr' => array('target' => '_top')));
Remember to pass your form model data (if any) as first argument.
Expanding on Debreczeni's answer; you can define the default options in your form class:
use Symfony\Component\OptionsResolver\OptionsResolver;
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'attr' => [
'target' => '_top',
],
]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.