I\'m trying to put html inside a form button with twig like:
{{ form_widget(form.jiraStatus, {
\'label\': \'Bug\',
this is how I solved and tested with Symfony 4. In twig template:
{{form_start(form)}}
{{form_widget(form)}}
{{form_end(form)}}
In my PHP controller form I did not add any button but just input fields.
$form = $this->createFormBuilder($article)
->add('title',TextType::class, array(
'data' => $article->getTitle(),
'attr' => array('class' => 'form-control')))
->add('body', TextareaType::class, array(
'data' => $article->getBody(),
'required' => false,
'attr' => array('class' => 'form-control')))
->getForm();
What I did to check the form submission is:
if($form->isSubmitted() ){
if($request->request->get('create') && $form->isValid()){
$article = $form->getData();
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($article);
$entityManager->flush();
} //l'alternativa può solo essere il cancel
return $this->redirectToRoute('article_list');
}
Hope this can help. Good to say that even the problem of buttons alignment is solved because div
is not added for every button as form add
method does.