Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony2确认表格提交_Symfony_Symfony 2.2 - Fatal编程技术网

Symfony2确认表格提交

Symfony2确认表格提交,symfony,symfony-2.2,Symfony,Symfony 2.2,我需要能够在表单数据持久化到数据库之前对其执行操作。问题是,操作可能有风险,每次我都需要用户的同意 我希望通过一个确认表单(带有一条解释发生了什么的小消息)来实现这一点,而不是通过Javascript确认窗口 如何实现此功能 以下是处理表单的控制器操作方法的示例: <?php public function indexAction(Request $request) { ... $form = $this->createFormBuilder($myEntity)

我需要能够在表单数据持久化到数据库之前对其执行操作。问题是,操作可能有风险,每次我都需要用户的同意

我希望通过一个确认表单(带有一条解释发生了什么的小消息)来实现这一点,而不是通过Javascript确认窗口

如何实现此功能

以下是处理表单的控制器操作方法的示例:

<?php
public function indexAction(Request $request)
{
    ...

    $form = $this->createFormBuilder($myEntity)
        ->add('someField', 'integer', array('required' => true))
        // Lots and lots of fields
        ->getForm();

    if ($request->isMethod('POST')) {
        $form->bind($request);

        if ($form->isValid()) {
            // CUSTOM VALIDATION HERE

            // If invalid, must display a new confirmation form to ask user
            // if it's alright to do a somewhat risky operation that would
            // validate the form data.

            // Else, persist the data.
            $db = $this->getDoctrine()->getManager();
            $db->persist($myEntity);
            $db->flush();

            return $this->redirect($this->generateUrl('my_path_to_success_page'));
        }
    }

    return $this->render('MyBundle:Preferences:index.html.twig', array(
        'form' => $form->createView(),
        'errors' => $form->getErrors(),
    ));
}

您可能需要查看,它允许您创建多步骤表单