LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   html: submitting form data as GET parameters instead of POST? (http://www.linuxquestions.org/questions/programming-9/html-submitting-form-data-as-get-parameters-instead-of-post-4175450035/)

stateless 02-13-2013 02:54 PM

html: submitting form data as GET parameters instead of POST?
 
Hi. I'm no expert at HTML, but I'm forced to become one because of a django project I have been assigned. I have a page which has a search box, which sends string data to a page over POST. However, it would simplify some other code if the form would send the data as GET parameters. (The search does not change the server/data, so this makes philosophical sense as well.) Is there some setting you change in the form HTML to make it do that, or do you have to use some kind of advanced Javascript? I know some search engine search boxes do this, but I'm not sure exactly how.

joe_2000 02-13-2013 04:14 PM

Hi. Just changeing the value of the method attribute from post to get should do the trick.

Code:

<form action="whatever" method="get">

theNbomr 02-14-2013 08:18 AM

Quote:

Originally Posted by joe_2000 (Post 4891067)
Hi. Just changeing the value of the method attribute from post to get should do the trick.

Code:

<form action="whatever" method="get">

This might work if the accordant code on the server is agile enough to determine what method was used. Don't know about Django, but the code that services the form may be hardwired to use one particular method. If you are replacing that code anyway, it won't really matter. The nature of the form often dictates the most appropriate method to use. Post requests may be more appropriate for larger volumes of data.

--- rod.

sundialsvcs 02-14-2013 06:03 PM

Generally speaking, POST is by-far more flexible in what sort of data it can easily transfer. You probably don't want to change it to use GET. Django is perfectly capable of handling data that arrives in either format .. in fact, it should not care. Figure out what you do not yet understand about Django, and do not (please do not take me wrongly here ...) "screw things up" because you don't yet.

You're barking up the wrong tree .. and about to make a big mistake. Learn more about Django. Don't do anything yet.

dugan 02-14-2013 10:39 PM

Sundiavlvcs, what does he not understand about Django, and what big mistake is he about to make?

stateless 02-15-2013 01:08 PM

Quote:

Originally Posted by sundialsvcs (Post 4891865)
Generally speaking, POST is by-far more flexible in what sort of data it can easily transfer. You probably don't want to change it to use GET. Django is perfectly capable of handling data that arrives in either format .. in fact, it should not care. Figure out what you do not yet understand about Django, and do not (please do not take me wrongly here ...) "screw things up" because you don't yet.

You're barking up the wrong tree .. and about to make a big mistake. Learn more about Django. Don't do anything yet.

Situation is basically this: I have a page that provides searches of data through a form, and the same page displays search results. Currently, the form sends search requests information over post. However, some search results, and sometimes even other pages, have hyperlinks which send in additional search information (i.e., new searches) through GET parameters in the hyperlink. So, in the backend, there has to be /both/ code for handling search request information received over POST and search request information received over GET.

So, naturally I wanted to simplify the code, by unifying this to one method or the other. GET makes more sense to me, because 1) I don't know how to have a hyperlink send parameters over POST, and 2) the searches do not change the database, and 3) if search request info is sent over GET, then search results can be "saved" through bookmarks. Now, if somebody has a better argument or a better approach, my ears are open.

theNbomr 02-15-2013 01:13 PM

sundialsvcs makes a good point. Please tell us how you expect anything to become simpler by changing the HTTP request method. Your use of the phrase 'which sends string data to a page over POST' makes me wonder how strong your understanding of HTTP is (since it is technically somewhat nonsensical; and I'm not trying to disparage you). It does sound like you may be trying to address a problem, or perceived problem from the wrong angle.

--- rod.

theNbomr 02-15-2013 01:17 PM

Quote:

Originally Posted by stateless (Post 4892464)
in the backend, there has to be /both/ code for handling search request information received over POST and search request information received over GET.

Any well crafted website should work this way, IMHO. It is the agility I referred to in a prior post.
--- rod.


All times are GMT -5. The time now is 04:01 AM.