Symfony2 Das CSRF-token ist ungültig. Bitte versuchen Sie es erneut die form

Ich habe ein Formular, das immer die "CSRF-token ist ungültig. Bitte versuchen Sie es erneut die form." Ich war nicht in der Lage, die Ursache zu finden.

Ich weiß, es ist etwas zu einfach. jede Hilfe würde geschätzt werden.

In der Steuerung habe ich dieses:

public function settingsAction()
{   
    $request = $this->getRequest();

    /* @var $user User */
        $user = $this->get('security.context')->getToken();

    $settingsForm = $this->createForm(new SettingsFormType(), array($user));
    $billingForm = $this->createForm(new BillingFormType(), array($user));
    $accountForm = $this->createForm(new AccountFormType(), array($user));



        return $this->render('DeductrDeductrBundle:Settings:settings.html.twig', array(
                'settingsForm' => $settingsForm->createview(),'billingForm' => $billingForm->createview(),'accountForm' =>$accountForm->createview(),));
}

public function createAction()
{
    $em = $this->getDoctrine()->getEntityManager();

    $form = $this->createForm(new RegistrationFormType('Deductr\UserBundle\Entity\User'));

    $form->bind($this->getRequest());

    if ($form->isValid()) {
        $user = $form->getData();

        $em->persist($user);
        $em->flush();

        return $this->redirect('/settings');
    }

Den .twig Datei diese:

{% extends 'DeductrDeductrBundle:Base:base.html.twig' %}


{% block body %}
<div name='personal' style="padding-left:25px; width:600px;">
<h5>Personal Information</h5>
{#src/Deductr/DeductrBundle/Resources/views/settings/settings.html.twig #}
<form action="{{ path('user_registration_create') }}" {{ form_enctype(settingsForm) }}" method="POST" {{ form_enctype(settingsForm) }}>

 <table>
        <tr>
            <td>First Name</td>

            <td>Last Name</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>
        {{ form_widget(settingsForm.first_name, {'attr': {'class' : 'half'}}) }}
            </td>

            <td>
                {{ form_widget(settingsForm.last_name, {'attr':    {'class' : 'half'}}) }}
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3">Company</td>
        </tr>
        <tr>
            <td colspan="3">
                {{ form_widget(settingsForm.company, {'attr': {'class' : 'half'}}) }}

            </td>
        </tr>
        <tr>
            <td colspan="3">Address 1</td>
        </tr>
        <tr>
            <td colspan="3">
                {{ form_widget(settingsForm.address1, {'attr': {'class' : 'half'}}) }}

            </td>
        </tr>
        <tr>
            <td colspan="3">Address 2</td>
        </tr>
        <tr>
            <td colspan="3">
                {{ form_widget(settingsForm.address2, {'attr': {'class' : 'half'}}) }}

            </td>
            </tr>
            <tr>
            <td colspan='2'>
                <label for 'city'>City</label>
            </td>
            <td>&nbsp;</td>

            </tr>

        <tr>
            <td colspan='2'>
                {{ form_widget(settingsForm.city, {'attr': {'class': 'half'}}) }}
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><label for 'state'>State</label>
            <td>
                <label for 'zip'>Zip/Postal</label>
            </td>
            <td>
                <label for 'phone'>Phone Number</label>
            </td>

        </tr>
            <tr>
            <td>
                {{ form_widget(settingsForm.province, {'attr': {'class': 'half'}}) }}
            </td>
            <td>
                {{ form_widget(settingsForm.postal_code, {'attr': {'class': 'half'}}) }}
            </td>
            <td>
                {{ form_widget(settingsForm.phone, {'attr': {'class': 'half'}}) }}
            </td>

        </tr>
        <tr>
    <td>&nbsp;</td>         
    <td>&nbsp;</td>
    <td><input type="submit" value="{{ 'submit'|trans({}, 'DeductrUserBundle') }}" /></td>
</tr>
 </table> 
 {{ form_row (settingsForm._token) }} 
</form>

</div>
<div id="billing" style="padding-left:25px; width:600px;">
<h5>Billing Information</h5>
<form action="" method="POST" {{ form_enctype(billingForm) }}>
    {{ form_row (billingForm._token) }}

 <table>
    <!--    <tr>
            <td>First Name</td>

            <td>Last Name</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>
        {{ form_widget(billingForm.fname, {'attr': {'class' : 'half'}}) }}
            </td>

            <td>
                {{ form_widget(billingForm.lname, {'attr': {'class' : 'half'}}) }}
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3">Address 1</td>
        </tr>
        <tr>
            <td colspan="3">
                {{ form_widget(billingForm.billingAddress1, {'attr': {'class' : 'half'}}) }}

            </td>
        </tr>
        <tr>
            <td colspan="3">Address 2</td>
        </tr>
        <tr>
            <td colspan="3">
                {{ form_widget(billingForm.billingAddress2, {'attr': {'class' : 'half'}}) }}

            </td>
            </tr>
            <tr>
            <td colspan='2'>
                <label for 'city'>City</label>
            </td>
            <td>&nbsp;</td>

            </tr>

        <tr>
            <td colspan='2'>
                {{ form_widget(billingForm.billingCity, {'attr': {'class': 'half'}}) }}
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><label for 'state'>State</label>
            <td>
                <label for 'zip'>Zip/Postal</label>
            </td>
            <td>
                <label for 'phone'>Phone Number</label>
            </td>

        </tr>
            <tr>
            <td>
                {{ form_widget(billingForm.billingState, {'attr': {'class': 'half'}}) }}
            </td>
            <td>
                {{ form_widget(billingForm.billingZip, {'attr': {'class': 'half'}}) }}
            </td>
            <td>
                {{ form_widget(billingForm.billingPhone, {'attr': {'class': 'half'}}) }}
            </td>

        </tr> -->
<tr>
    <td colspan='3'>
     <h5>Payment Information</h5>
    </td>
</tr>
    <tr>
        <td>Expiration Date</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
        <tr>
        <td>{{ form_widget(billingForm.expMonth, {'attr': {'class': 'half'}}) }}</td>
        <td>{{ form_widget(billingForm.expYear, {'attr': {'class': 'half'}}) }}</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
    </tr>
    <tr>
        <td>Credit Card Type</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
        <tr>
        <td>{{ form_widget(billingForm.ccType, {'attr': {'class': 'half'}}) }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
    </tr>
    <tr>
        <td>Credit Card Number</td>
        <td>&nbsp;</td>
        <td>CVV</td>
    </tr>
        <tr>
        <td>{{ form_widget(billingForm.cardNumber, {'attr': {'class': 'half'}}) }}</td>
        <td>&nbsp;</td>
        <td>{{ form_widget(billingForm.cvv, {'attr': {'class': 'half'}}) }}</td>
    </tr>
    <tr>
    </tr>
<tr>
    <td>&nbsp;</td>         
    <td>&nbsp;</td>
    <td><input type="submit" value="{{ 'submit'|trans({}, 'DeductrUserBundle') }}" /></td>

</tr>
</table>
</div>
</form>

</div>
<div id="account" style="padding-left:25px; width:600px;">
<h5>Account Information</h5>
<form action="" method="POST" {{ form_enctype(accountForm) }}>
    {{ form_row (accountForm._token) }}
<table>
    <tr>
        <td colspan='2'>Email</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td colspan='3'>{{ form_widget(accountForm.email, {'attr': {'class': 'half'}}) }}</td>
    </tr>
    <tr>
        <td colspan='2'>Password</td>
        <td>Confirm Your Password</td>
    </tr>
    <tr>
        <td>{{ form_widget(accountForm.password, {'attr': {'class': 'half'}}) }}</td>
        <td>&nbsp;</td>
        <td>{{ form_widget(accountForm.confPass, {'attr': {'class': 'half'}}) }}</td>
    </tr>
    <tr>
    <td colspan='2'>&nbsp;</td>
    <td><input type="submit" value="{{ 'submit'|trans({}, 'DeductrUserBundle') }}" /></td>

</tr>
</table>
 </form>
</div>
{% endblock %}
InformationsquelleAutor Adam Mills | 2013-04-12
Schreibe einen Kommentar