【问题标题】:symfony get selected choiceType valuesymfony 获取选择的choiceType 值
【发布时间】:2018-04-28 15:33:18
【问题描述】:

您好,我正在开发 symfony 3.3 项目。我有一个带有choiceType 的表单,我想知道阅读所选选项的正确方法是什么

控制器代码

$form = $this->createFormBuilder()
        ->add('decision', ChoiceType::class, array('choices'  => array(
        'valider' => 'valider',
        'rejeter' => 'rejeter',
    )

    ))
        ->setAction($this->generateUrl('validerRejeter', array('id' => $cours->getId())))
        ->setMethod('POST')
        ->getForm();

  $form->handleRequest($request); 
  if ($form->isSubmitted() && $form->isValid())
  {
    $choix=$request->request->get('form');
    if ($choix == 'valider')
        $cours->setEtat('publié');
    else 
        $em->remove($cours);
        $em->flush();
    }

【问题讨论】:

    标签: php symfony symfony-3.3


    【解决方案1】:
    $choix = $form->get('decision')->getData();
    

    $choix = $request->request->get('decision');
    

    【讨论】:

      猜你喜欢
      • 2022-11-24
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 2014-10-30
      相关资源
      最近更新 更多