We have the unusual requirement of a multi-step form through GET requests. So, instead of POSTing the forms, we’re using GET requests to pass new parameters to the query. So, the basic idea is that there’s a treatment, and a date passed to the query. A three-step form if you will.
- Show available treatments, pick one
- Show available dates (there’s business logic in the background that figures these out)
- Pick a time
The URL will go through the following states
- site.com/bookings/new
- site.com/bookings/new/[id|name_of_treatment] (by this, I mean it could either by the ID field or the name of the the treatment)
- site.com/bookings/new/[id|name_of_treatment]/2010-12-12/
So, my route looks like this:
map.connect 'bookings/new/:massage_type/:date', :controller => :bookings, :action => :new
massage_type is synonymous with the treatment_id.
So my form_tag looks like this:
<% form_tag( {:action => "new"}, :method => "get" ) do %>
The problem I’m having is that I want it to just give me back the URL site.com/bookings/new/[id|name_of_treatment]/ but instead it gives back the following URL:
http://localhost:3000/bookings/new?massage_type[treatment_id]=1&commit=actionnew
I don’t suppose anyone knows?
Forms that use
GETare adding the input values as query parameters. There’s no way to make the form post to a different URL, where the input values are part of the URL instead – it’s just not supported by the HTML standard.You could use URL rewrite to remap the incoming URLs of this type to the one you want, however that’s not really a good solution, because this would result in a second request.
However, what I don’t understand is why does the form need to do
GETto that specific URL. Is it a requirement that these URLs can be constructed by the user manually, instead of using the form?If there is no such requirement, I would advise to use standard
POSTform tohttp://localhost:3000/bookings/newand modify the form in the response based on the parameters in thePOSTbody, as necessary.Better yet, write some Ajax that would update the form according to the user’s choice, without making a full form submit, until the user has finished all the choices.