表格不在symfony中提交

时间:2016-11-11 18:57:18

标签: forms symfony submit

在我的控制器中,我有:

public function indexAction(Request $request)
    {
        $participantEntry = new Participants();

    $form = $this->createForm(ParticipantsType::class, $participantEntry,[
        'action' => $request->getUri()
    ]);


    $form->handleRequest($request);

    if($form->isValid())
    {
        $em = $this->getDoctrine()->getManager();
        $em->persist($participantEntry);
        $em->flush();
    }

    return $this->render('SurveyBundle:Page:index.html.twig',
        ['form' => $form->createView()]);
}

使用此buildForm创建表单:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
    $builder
        ->add('gender', ChoiceType::class, array(
            'choices'  => array(
                'Male'   => 1,
                'Female' => 2,
            ),
            'expanded' => true,
            'multiple' => false
        ))
        ->add('audio1', ChoiceType::class, array(
            'choices'  => array(
                'Happy'   => 1,
                'Surprised' => 2,
                'Sad' => 3,
                'Angry' => 4,
                'Disgust' => 5,
                'Scared' => 6,
            ),
            'expanded' => true,
            'multiple' => false
        ))
        ->add('age', ChoiceType::class, array(
            'choices'  => array(
                'Less than 18'   => 1,
                '18 - 24' => 2,
                '25 - 34' => 3,
                '35 - 44' => 4,
                '45 - 54' => 5,
                '55 and over' => 6,
            ),
            'expanded' => true,
            'multiple' => false
        ))
        ->add('ethnicity', ChoiceType::class, array(
            'choices' => array(
                'White / Caucasian' => 1,
                'Hispanic / Latino' => 2,
                'Asian' => 3,
                'Black / African American' => 4,
                'Other' => 5,
            ),
            'expanded' => true,
            'multiple' => false
        ))
        ->add('submit',SubmitType::class);

}

然后在我的Twig文件中将问题显示为RadioButtons。

但是,当我点击提交并选择了所有内容时,表单实际上并未提交。我究竟做错了什么?

0 个答案:

没有答案