简体   繁体   中英

Error when submitting a form Symfony 2

Please can someone tell me why I get an error.

public function trainingAction()
{
    $em = $this->getDoctrine()->getManager();

    $Date = new AcademyTraining();
    $Date->setDate(new \DateTime('tomorrow'));
    $Time = new AcademyTraining();
    $Time->setTime();
    $Topics = new AcademyTraining();
    $Topics->setTopics('');
    $Leader = new AcademyTraining();
    $Leader->setLeader('');
    $Details = new AcademyTraining();

    $Dateform = $this->createFormBuilder($Date)
        ->add('date', DateType::class, array(
            'label' => false,
            )
        )
        ->getForm();

    $Timeform = $this->createFormBuilder($Time)
        ->add('time', TimeType::class, array(
            'input'  => 'datetime',

            'label' => false,
            )
        )
        ->getForm();

    $Topicsform = $this->createFormBuilder($Topics)
        ->add('Topics', TextType::class, array(
            'label' => false,
            )
        )
        ->getForm();

    $Leaderform = $this->createFormBuilder($Leader)
        ->add('Leader', ChoiceType::class, array(
            'choices' => array(
                'name' => 'Name',
                'name2' => 'Name 2'
            ),
            'label' => false,
            )
        )
        ->getForm();


    $SessionSubmitForm = $this->createFormBuilder($Details)
        ->add('save', SubmitType::class, array( array('label' => 'Save Changes'))
        )
        ->getForm();

    $user = $this->get('security.token_storage')->getToken()->getUser();
    $applicantstatus = $user->getApplicantStatus();



    if ($SessionSubmitForm->isSubmitted() && $SessionSubmitForm->isValid()) {

        $Details = $Leaderform->getData();
        $Details = $Dateform->getData();
        $Details = $Timeform->getData();
        $Details = $Topicsform->getData();

        $em = $this->getDoctrine()->getManager();
        $em->persist($Details);
        $em->flush();

        return $this->redirectToRoute('task_success');
    }

    return $this->render('AppBundle:Academy/Applicants:trainingPTSpage.html.twig', array(
        'Timeform' => $Timeform->createView(),
        'Topicsform' => $Topicsform->createView(),
        'Dateform' => $Dateform->createView(),
        'Leaderform' => $Leaderform->createView(),
        'officers' => $em->getRepository('AppBundle:TrainingParticipants')->findAll(),
        'session' => $em->getRepository('AppBundle:AcademyTraining')->findAll(),
        "applicantstatus" => $applicantstatus

    ));

}

The error is:

The option "0" does not exist. Defined options are: "attr", "auto_initialize", "block_name", "disabled", "label", "label_format", "translation_domain", "validation_groups"

This form is used to read in details for a training session. It use's Symfony to generate the form. I have made separate forms for each of the fields. I believe I might have the formatting wrong for the forms and the properties of them however I'm not sure that is the reason for the error.

You have a multidimensional array, you must declare an associative array, like this:

$SessionSubmitForm = $this->createFormBuilder($Details)
    ->add('save', SubmitType::class, array('label' => 'Save Changes')
    )
    ->getForm();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM