stacheldraht27
stacheldraht27

Reputation: 392

GET method in form returns wrong URL

I have a simple form with method="get" and action="?subject=search_result&":

<form class="form" id="searchform" name="searchform" action="?subject=search_result&" method="get">
    <input type="text" name="search" class="form-control" placeholder="Search for...">
    <button class="btn btn-default" type="submit">Go!</button>                            
</form>

it only return

?search=blablabla

instead of

?subject=search_result&search=blablabla

Upvotes: 1

Views: 188

Answers (2)

theark
theark

Reputation: 339

You can use the hidden input field to set the extra parameters and you can remove the action attribute. The default method is GET, that can also be avoided as shown below:-

<form class="form" id="searchform" name="searchform">
   <input type="hidden" name="subject" value="search_result">
    <input type="text" name="search" class="form-control" placeholder="Search for...">
    <button class="btn btn-default" type="submit">Go!</button>                            
</form>

Upvotes: 1

Zerium
Zerium

Reputation: 17333

You can just do this:

<form class="form" id="searchform" name="searchform" action="" method="get">
  <input type="text" name="search" class="form-control" placeholder="Search for...">
  <button class="btn btn-default" type="submit">Go!</button>
  <input type="hidden" name="subject" value="search_result">                         
</form>

Notice the <input type="hidden". This will give you both search and search_result inside your URL.

Upvotes: 1

Related Questions