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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程