Jump to content

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


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!

Edited by Donotknow
Link to post
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 post
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?

Edited by Donotknow
Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...