Id attribute on form tag symfony
Solution 1:
Have you tried attr
?
{{ form_start(form, {'attr': {'id': 'form_person_edit'}}) }}
Solution 2:
Inject the id in the options array that is passed into the form builder:
public function newAction(Request $request)
{
// create a task and give it some dummy data for this example
$task = new Task();
$task->setTask('Write a blog post');
$task->setDueDate(new \DateTime('tomorrow'));
$form = $this->createFormBuilder($task, ['attr' => ['id' => 'task-form']])
->add('task', 'text')
->add('dueDate', 'date')
->add('save', 'submit', ['label' => 'Create Post'])
->getForm();
return $this->render('AcmeTaskBundle:Default:new.html.twig', [
'form' => $form->createView(),
]);
}
Or in a form type:
class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('task')
->add('dueDate', null, ['widget' => 'single_text'])
->add('save', 'submit');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults([
'data_class' => 'Acme\TaskBundle\Entity\Task',
'attr' => ['id' => 'task-form']
]);
}
public function getName()
{
return 'task';
}
}