![](/img/trans.png)
[英]Symfony 2 Form error “This form should not contain extra fields.” when submitting a form
[英]Error when submitting a form Symfony 2
請有人告訴我為什么會出錯。
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
));
}
錯誤是:
選項“ 0”不存在。 定義的選項包括:“ attr”,“ auto_initialize”,“ block_name”,“ disabled”,“ label”,“ label_format”,“ translation_domain”,“ validation_groups”
該表格用於詳細閱讀培訓課程。 它使用Symfony生成表單。 我為每個領域都做了單獨的表格。 我相信表單和屬性的格式可能不正確,但是我不確定這是錯誤的原因。
您有一個多維數組,必須聲明一個關聯數組,如下所示:
$SessionSubmitForm = $this->createFormBuilder($Details)
->add('save', SubmitType::class, array('label' => 'Save Changes')
)
->getForm();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.