tags:

views:

82

answers:

2

I have a PHP MVC Web App and Apache mod_rewrite rules already working fine, but when I create forms using method="get", the submitted URL looks like

contact/submit?a=b&c=d

I would like my form to submit to

contact/submit/a/b/c/d

Both posting and getting the form work fine on the server side, but when using post method, the back button always asks for reposting the form values and furthermore I want the strings in the URL for SEO. I think JQuery might let me intercept the form submit event and refresh to the url dynamically, but it it seems there must be an easier way to do it that I am missing.

A: 

You could use the POST->REDIRECT->GET pattern that Spring Web Flow utilizes. This would allow you to post as you wish and then redirect to contact/submit/a/b/c/d. It would also solve the problem with the back button asking you if you want to resubmit your form data. See this related article.

Taylor Leese
A: 

The GET method uses standard query string arguments to pass form data via an HTTP GET request.

The HTTP GET request is not intended to modify any data on the server. POST is designed for modifying data on the server.

GET may be cached. POST will not.

/a/b/c/d is not a standard format (as in RFC) for passing data. However, for requesting data or URLs to post to, that has become popular.

So, if you are updating server data, just use a POST -> REDIRECT -> /a/b/c/d.

If you are just reading data from the server, then you will need to use a bit of Javascript to read your form values and construct a query string, and then go to it with window.location = ...

Have fun!

gahooa