Atributo Id en la etiqueta de formulario symfony
Me gustaría definir un atributo id en mis formularios symfony2.
He intentado con esto en mi plantilla de ramita:
{{ form_start(form, {'id': 'form_person_edit'}) }}
Pero parece que no funciona.
49
3 answers
¿has probado attr
?
{{ form_start(form, {'attr': {'id': 'form_person_edit'}}) }}
94
Author: SirDerpington,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-05 15:30:14
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-05 15:30:14
Inyecte el id en la matriz de opciones que se pasa al constructor de formularios:
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(),
]);
}
O en un tipo de formulario:
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';
}
}
21
Author: jcroll,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-11 14:21:15
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-11 14:21:15
Además, debo agregar a las respuestas mencionadas anteriormente, que puedes hacerlo en tu controlador de esta manera:
$this->createForm(FormTypeInterFace, data, options);
Para una muestra - hice esto así:
$this->createForm(registrationType::class, null, array(
'action' => $this->generateUrl('some_route'),
'attr' => array(
'id' => 'some_id',
'class' => 'some_class'
)
));
3
Author: Stephan Yamilov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-05 08:31:07
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-05 08:31:07