0
在我的控制器中,有一个基于Doctrine CRUD生成的相当经典的“创建”操作。symfony controllerAction持续几次相同的对象
但是,当我通过点击“创建”表单按钮多次执行此操作时,同样的对象被创建多次,因为我点击。
这是一个主要问题,因为我的班级“操作”非常大,需要很长时间来记录。用户非常想要点击几次。
/**
* Creates a new Operation entity.
*
* @Route("/", name="operation_create")
* @Method("POST")
* @Template("MyApplicationBundle:Operation:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new Operation();
$form = $this->createForm(new OperationType(), $entity, array(
'em' => $this->getDoctrine()->getManager(),
));
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity->setdateCreation(new \DateTime())
->setUser($this->get('security.context')->getToken()->getUser());
$em->persist($entity);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'OK');
return $this->redirect($this->generateUrl('operation_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
如果任何人都可以帮助我,这将是非常好的。
通过javascript首次点击后,禁用按钮? –
可能的重复http://stackoverflow.com/questions/926816/how-to-prevent-multiple-form-submit-from-client-side http://stackoverflow.com/questions/2830542/prevent-double-submission -of-表单中,jQuery的 – zizoujab