I have a form that I'd like to use in several pages of my website. So I call the method like that in my page:
{{ render(controller('ProjectApplicationBundle:Application:form')) }}
And I have my formAction method:
public function formAction()
{
$form = $this->createForm($type,$obj);
if('POST' == $this->getRequest()->getMethod()){
$form->submit($this->getRequest());
if($form->isValid()){
//redirect to a page after the form
}
}
//render the form template ...
}
This is not my code, this is just an example.
So I add to create a route to send my form
project_application_form:
pattern: /form
defaults: { _controller: ProjectApplicationBundle:Application:form }
Now my problem :)
1) I'd like to block the access to my form using the url, just allow for the data processing.
2) in case of error the page is not redirect, so the form is display without layout, so I'd like to get the form with errors in the page that I render the form.
EDIT: I maybe have a solution for the second point but this is not very proper. set in argument of my render the route and return to the route instead of render render the form. Finally I use a session to put the error.
I hope this is clear for you, sorry for my english.
You'll have to secure the action where you process your form and make it available only by
POST
Example :
If you use
yml
syntax for the route, it's gonna be :Open a new question for your 2) point because only one question per thread and it's an other problematic