doucheng4660 2014-10-27 20:18
浏览 32
已采纳

表格不提交 - Symfony2

why does my symfony2 Form not submit? If i press the submit-button, nothing happens.

I want not the default-form {{ form(form) }}. The default form works. The error seems to be in TWIG?

{% extends '::base.html.twig' %}
{% block stylesheets %}
    {{ parent() }}

    <link href="{{ asset('css/essensplan/show.css') }}" rel="stylesheet" />
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">


{% endblock %}

{% block body -%}

{{ form_start(form)  }}

    <h1>Speiseplan für KW {{ kw }}</h1>

        <form action = "" method = "post">
            <input type="submit" name="back" value="<" class="btn-lg btn-success"/>
            <input type="submit" name="next" value=">" class="btn-lg btn-success" />

            <input type="hidden" name="kw" value="{{ kw }}">
        </form>

        <div class="container-fluid">

        <div class="tag col-xs-3">
                <div class="wochentag">
                Montag
                </div>
                <div class="hauptgericht">
                         <div class="h"><strong>Hauptgericht</strong></div>
                         <div class=""> {{ form_widget(form.montagHauptgericht) }}
                          </div>

                </div>
                <div class="nachtisch">
                         <div class="n"><strong>Nachtisch</strong></div>
                         <div class=""> {{   form_widget(form.montagNachtisch) }} </div>
                </div>
        </div>


        </div>
        {{ form_widget(form.Eintragen)  }} 

        {{ form_end(form) }}
{% endblock %}


<?php

namespace Chris\TestBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Chris\TestBundle\Entity\KW;
use Chris\TestBundle\Form\KWType;
use Symfony\Component\HttpFoundation\Session\Session;

/**
 * Admin controller.
 *
 */
class AdminController extends Controller
{

    /**
     * Lists all KW entities.
     *
     */
    public function adminAction(Request $request)
    {
        $jahr = "2014";
        $kw = "43";

        // $_GET parameters

        // Änderung
        if ($request->get('next')){
            $kw = (intval($request->get('kw'))+1) . "";
            //var_dump($kw);
        }
        if ($request->get('back')){
            $kw = (intval($request->get('kw'))-1) . "";
            //var_dump($kw);
        }


        $form = $this->createFormBuilder()
        ->add('montagHauptgericht', 'text')
        ->add('montagNachtisch', 'text')
        ->add('Eintragen', 'submit')
        ->getForm();

        $form->handleRequest($request);

            // data is an array with "name", "email", and "message" keys
            $data = $form->getData();


        return $this->render('ChrisTestBundle:KW:admin.html.twig', array(
            'form' => $form->createView(), 'kw' => $kw
        ));
    }

}

Thanks for your help.

  • 写回答

1条回答 默认 最新

  • dougu3290 2014-10-27 20:22
    关注

    It seems that you have nested forms in your markup (first one coming from twig's {{ form }} second is in markup. According to this or this you are not allowed to nest form tags. This might be the reason your form is not submitting properly

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化