Mikado Joe
Mikado Joe

Reputation: 183

Form does not submit - 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.

Upvotes: 0

Views: 2098

Answers (1)

Tomasz Madeyski
Tomasz Madeyski

Reputation: 10890

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

Upvotes: 1

Related Questions