Calls to isSumbitted() and isValid() result in “undefined method” error

前端 未结 1 1193
北恋
北恋 2021-01-29 07:17

I have a Symfony form that is created from createFormBuilder() in the controller. But under two IF statements the form should carry two different set of fields. My Symfony versi

相关标签:
1条回答
  • 2021-01-29 08:02

    Try:

    $formbuilder = $this->createFormBuilder()
            ->add('name', TextType::class, ['required' => true]])
            ->add('email', EmailType::class, ['equired' => true]]);
    
    if($a==true){
        $formbuilder->add('username', TextType::class, ['required' => true]])
             ->add('password', PasswordType::class, ['required' => true]]);
    }
    
    $form = $formbuilder->getForm();
    
    if ($form->isSubmitted() && $form->isValid()) {
            ...
            ...
            ...
    }
    
    0 讨论(0)
提交回复
热议问题