Bv202
Bv202

Reputation: 4054

Getting correct URL when using GET

When clicking a button, I would like my URL to become this:

users.php?action=search&formvar1=value&formvar2=value&...

This is what I've tried:

<form id="search" action="users.php?action=search" method="get">

But this doesn't seem to work (it doesn't add the action=search part). Is there any way to do this? I know it works when using POST instead of GET, so why wouldn't it here?

Thank you

Upvotes: 1

Views: 77

Answers (2)

mario
mario

Reputation: 145512

You can do that similarly to a POST form. Simply include the default attribute as hidden form field:

<form id="search" action="users.php" method="get">
<input type="hidden" name="action" value="search">

This way it will be added as parameter to the URL like all other variables.

Upvotes: 6

SLaks
SLaks

Reputation: 888273

The browser is building the query string from scratch.

Instead, you can add an <input type="hidden" name="action" value="search" />.

Upvotes: 1

Related Questions