When Submitting a Get Form, the Query String Is Removed from the Action Url

Form submission with a ?key=val query string already in the action attribute ignores that query string

I know this is an old question, but the solution is actually pretty simple (and neat!).

All you have to do is sending the querystring with hidden input fields in the format name="key" and value="value".

?brandcode=JM&t=cat_items would "translate" into:

<input type="hidden" name="brandcode" value="JM" />
<input type="hidden" name="t" value="cat_items" />

Completely remove the querystring from your action.

Query string lost from a submit button

The problem is with the form:

<form name="helloButton" action="hello?id=100" method="get">
<input type="submit" value="Hello">

As the form method is set to get, it's changing the query string. method="get" tells the browser to add the contents of the form to the query string which means the current query string gets removed.

You can add the ID as a hidden field in the form like this:

<form name="helloButton" action="hello" method="get">
<input type="hidden" name="id" value="100">
<input type="submit" value="Hello">

That will tell the browser to add the hidden field to the query string resulting in hello?id=100. Alternatively you could change the form method to POST.

How to remove 'GET?' string from URL when submitting a GET form

You specified this as action="GET", this is the URL where the form will submit to, you should specify method="GET", or just nothing, since that is the default method, so:

<section id="brand-list">
<form method="GET">
<input type="text" name="keyword">

GET form action with URL parameter gets removed on form submission

When you use method="get", you can't put values in the query string of the action. They will be replaced by the values from the form fields when you post the form.

Put the values in hidden fields instead:

<form method="GET" action="a.php">
<input type="hidden" name="r" value="1">
<input type="radio" name="go" value="1">

POST forms: How to put GET parameters in action attribute?

If you absolutely need to put it on action attribute you can use method="POST".

<!DOCTYPE html>
<form action="draft.html?test=1" method="POST">
<button type="submit">Valid</button>

Otherwise if you want to send your data trough GET use

<!DOCTYPE html>
<form action="draft.html" method="GET">
<input type="hidden" name="test" value="1">
<button type="submit">Valid</button>

PHP form action is not working and is not updating querystring

Your form is overriding the query string parameters in your action attribute.

Instead of putting the query string in the action, add a hidden field

<form class="filter_form" method="get" action="index.php">
<!-- ... the rest of your form code -->
<input class="button filter_button" type="submit" value="filter" />
<input type="hidden" name="page" id="page" value="agenda" />

Related post: submitting a GET form with query string params and hidden params disappear

Form doesn't take me to action url when submitting

You almost have it. All you need to do is to move the "action" and "method" attributes into the form tag instead of the div.

Since you don't have the "action" in the form tag, the default behavior is to submit the form to the same page.

Related Topics

Leave a reply