This topic contains 0 replies, has 1 voice, and was last updated by scivray 8 years, 7 months ago.
- Topic
Hello,
I have a simple Entity and I would like to use a simple Form to create new objects.
I added 2 submit buttons to my form, one to save and go back to grid and another to save and create a new one (http://symfony.com/blog/new-in-symfony-2-3-buttons-support-in-forms)Extract of my ClientType.php
$builder->add('save', 'submit',
array(
'label' => 'cl.poc.client.form.save',
)
)->add('saveAndAdd', 'submit',
array(
'label' => 'cl.poc.client.form.saveAndAdd',
)
);In my controller, my action is the following :
public function createAction(Request $request)
{
$client = new Client();$form = $this->createForm(new ClientType(), $client);
if($request->getMethod() == 'POST'){
$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid())
{
$this->getDoctrine()->getManager()->persist($client);
$this->getDoctrine()->getManager()->flush();
$this->get('session')->getFlashBag()->add(
'notice',
'Nouveau client créé !'
);if ($form->get('save')->isClicked()) {
return $this->redirect($this->generateUrl('cl_poc.client.index', array()));
}
else {
if ($form->get('saveAndAdd')->isClicked()) {
return $this->redirect($this->generateUrl('cl_poc.client.create', array()));
}
else {
// TODO ERROR TO BE CATCH
return $this->redirect($this->generateUrl('cl_poc.client.index', array()));
}
}
}
}return $this->render('CLPocBundle:Client:create.html.twig', array(
'form' => $form->createView(),
));
}
The form is printed this way in create.html.twig :
{% extends 'OroUIBundle:Default:index.html.twig' %}
{% block content %}
{{ form(form) }}
{% endblock %}
My problem is that my
$form->get('save')->isClicked()
or$form->get('saveAndAdd')->isClicked()
always return false.I tried this :
{% block content %}
{{ form(form) }}
{% endblock %}
and this time isClicked() works as expected.Could you please explain me what I am missing in order to have isClicked() working with
{% extends 'OroUIBundle:Default:index.html.twig' %}
?Thank you.
Regards.
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.