We are developing two separate sites on Symfony2 and encountered a strange problem on both of them when processing submitted forms.
Both sites have an action that is used for both displaying the form and handling submission. As it handles both GET and POST requests, $this->getRequest()->getMethod() is checked. If it is GET, we display the form. If it is POST, we persist it into an entity.
However, getMethod() seems to always return GET even when posting the data. I know the request method should be POST because the browser’s network inspector says it sent the form as a POST request and var_dump($_POST); outputs the contents of the form we just submitted.
The sites are running on separate servers, both CentOS 6.3. I have a third similar server running a third site which handles the submissions fine. What could be causing this?
I’ve had such a problem several times and tried different approaches to it. Here’s my last one:
Note that you need to get the request as a parameter in this case — instead of fetching it from the container. If you’re using Symfony idiomatically, then you’re doing that already.
If you’ll ever find a better way of solving this problem, I’m eager to know it. 🙂