0

I am new in symfony2, I wanted to create a simple form and here is my code : in the controller :

    public function testAction(Request $request) {    
    $form = $this->createFormBuilder()
    ->add('name','text')
    ->add('age','integer')
    ->add('save','submit')
    ->getForm()
    ;//initializing the form
     return $this->render('LoginLoginBundle:Default:test.html.twig', array     ('myform'=>$form->createView()));
}  
}

in the twig file:

{%extends "::base.html.twig"%}
{% block body %}
{{ form(myform)}} 
{% endblock %}

I get this error : Could not load type "submit" and even if I delete ->add('save','submit') I get this error :

The function "form" does not exist. Did you mean "form_row", "form_rest", "form_label", "form_errors", "form_widget", "form_enctype" in LoginLoginBundle:Default:test.html.twig at line 3

1 Answer 1

3

I think you have Symfony 2.2 you should update it to 2.5. But if you want to keep your version, you must read this doc. They tell you you need to render your form with this code :

{% extends "::base.html.twig"%}
{% block body %}
    <form action="{{ path('your_route') }}" method="post" {{ form_enctype(myform) }}>
        {{ form_widget(myform) }}

        <input type="submit" />
    </form>
{% endblock %}

(You can see that the "submit" button must be rendered in the template and that you can't add it in your controller with your version of Symfony)

Sign up to request clarification or add additional context in comments.

1 Comment

thx, it works,I don't want to update because I will have trouble in dependencies with other vendors. but please edit 'form' to 'myform' to show that this is the passed variable. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.