Jump to content

[SOLVED] Correct usage of sending data by 'GET'


NoUser2U

Recommended Posts

Dear all,For some time now i'm using the <form> element in this matter:<form method="post" action=?controller=example1&method=example2>I'd like to send data via the 'GET method', but it is essential that the querystring is placed AFTER the action, for example, let's say i have:

<form method="get" action="?controller=search&method=getinput">	<input type="text" name="input" />		<input type="text" name="input2">		... some more inputs etc. etc. ...	<input type="submit" value="Submit" /></form>

Now what i'd like to have is, after pressing the submit button, my url to look like: "http://example.com?controller=search&method=getinput&input=...&input2=....&etc etc etcThe way it is right now is, when i press the submit button, the url will look like: "http://example.com?input=...&input2=...It somehow completely ignores the 'action' attribute specified in the <form> element.How do i solve this? Thnx in advance!

Link to comment
Share on other sites

You have to add the parameters as inputs of the form. Leaving the action empty will send the form to the same page.

<form method="get" action="">	<input type="hidden" name="controller" value="search" />	<input type="hidden" name="method" value="getinput" />	<input type="text" name="input" />	<input type="submit" value="Submit" /></form>

Link to comment
Share on other sites

Thnx for your fast reply Ingolme,I had thought of that and tried it, which worked, but is that the only way possible?How do other sites do it? for example, when you fill in a form and press enter. Then the site redirects you to some page and you see a very long dynamically generated url. It's hard to imagine such a site has a whole load of hidden fields in order to generate the custom url, right?In other words: is there no other 'clean and correct' way to do it?

Link to comment
Share on other sites

Thnx for your fast reply Ingolme,I had thought of that and tried it, which worked, but is that the only way possible?How do other sites do it? for example, when you fill in a form and press enter. Then the site redirects you to some page and you see a very long dynamically generated url. It's hard to imagine such a site has a whole load of hidden fields in order to generate the custom url, right?In other words: is there no other 'clean and correct' way to do it?
They possibly have PHP scripts to generate HTML for the fields.That's the only way to add parameters to the query string in a form using the GET method.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...