2
$form = $this->createForm(new OrganizationType(), $entity, array(
        'action' => $this->generateUrl('_control_organization_create'),
        'method' => 'POST',
    ));

    $form->add('submit', 'submit', array('label' => 'Create'));

    return $form;

there is action and method defined. how to get this? in template engine twig into custom render?

2 Answers 2

3

By calling,

{{ form(form) }}

Or,

{{ form_start(form) }}

the action and method options values you added to your form definition are used.

From the documentation ...

Also, check Building The Form section of the documentation to see how to render the HTML form by passing

array('form' => $form->createView()) 

to the render helper within your controller.

Then, take a look at Rendering the Form part of the same documentation.

Also ...

If you want to override them in your template, you've to pass the right values to your form() or form_start() helpers as follow,

{{ form(form, {'action': path('target_route'), 'method': 'GET'}) }}

{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
Sign up to request clarification or add additional context in comments.

1 Comment

i just need get custom render like this but how to get my custom array element {my action}, {my method}?<form action="{{ path('task_new') }}" method="post" {{ form_enctype(form) }}> {{ form_errors(form) }} {{ form_row(form.task) }} {{ form_row(form.dueDate) }} {{ form_rest(form) }} <input type="submit" /> </form>
0
Return your form like this

return $this->render('Your Bundle name: Your controller name : Your twig file', array(
            'form' => $form->createView(),
        ));


And in your twig file get the form like this:

{{ form(form) }}

Comments

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.