【问题标题】:Symfony 3 don't send the formSymfony 3 不发送表单
【发布时间】:2016-11-29 20:29:44
【问题描述】:

我正在 Symfony 3.1.7 中创建博客,但发送表单时遇到问题。我创建了评论实体类。然后我通过控制台端编辑的 buildForm 方法生成了表单类。它看起来像:

    public function buildForm(FormBuilderInterface $builder, array $options)
{
   $builder
      ->add('content')
      ->add('save',ButtonType::class);
}

我的控制器是这样的

/**
 * @Route("/article/{id}", name="show_article")
 */
public function showAction( Post $post, Request $request )
{
$comment = new Comment;
$comment -> setPost($post);
$form = $this->createForm(CommentType::class);
$form->handleRequest($request);

if ($form->isSubmitted() ) {
  $em = $this->getDoctrine()->getManager();
  $em->persist($comment);
  $em->flush();
}
        return $this->render('default/show.html.twig',[
  'post' => $post,
  'form' => $form -> createView()
]);
}

表格由twig helper {{form(form)}}显示。

问题是当我尝试发送表单时。我点击了按钮 什么都没有发生。看起来表单从未提交过。

感谢您的帮助。

【问题讨论】:

    标签: forms twig symfony


    【解决方案1】:

    像这样使用 SubmitType:

    ->add('save',SubmitType::class);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 2019-08-06
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    相关资源
    最近更新 更多