Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add additional parameters on a form, submitting it with GET method

Tags:

html

I have this form :

<form method='GET' name='search' action='index.php?explore=search'>      <input type="hidden" name="searchType" value="all" />     <input class="inputSearchSmall" name="search"> </form> <a href="javascript:document.search.submit()"><img src="img/button_search.png" class="buttonSearch" /></a> 

and I'd like to add parameters on the query string, after the action link. So, the result must be:

http://localhost:8080/website/index.php?explore=search&searchType=all&search=example 

not :

http://localhost:8080/website/index.php?searchType=all&search=example 

what's the best way to do this? Adding a hidden param like :

<input type="hidden" name="explore" value="search" /> 

Or can I concatenate the parameters to the action script in some way?

like image 529
markzzz Avatar asked Nov 05 '11 17:11

markzzz


People also ask

Can I submit form with GET method?

The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs. The length of a URL is limited (about 3000 characters)

Which method is used to get values from a submitted form?

There are two kinds of HTTP methods, which are GET and POST. The method attribute can be used with the <form> element. Attribute Values: GET: In the GET method, after the submission of the form, the form values will be visible in the address bar of the new browser tab.

How do you add an element to a form?

Create new elements by means of document. createElement() , and use appendChild() to append each of them to the container.

Which form attribute is used to sumbit the form data?

The method attribute specifies the HTTP method to be used when submitting the form data. The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ).


1 Answers

Adding them via a hidden param like you've suggested is the best way to go. It's more maintainable than adding to the form's action attribute value, and will do exactly what your asking. Just make sure you put it within the form tags.

like image 131
Todd Avatar answered Oct 01 '22 15:10

Todd