Hello Folks,

How to rid GET METHOD from echoing the submitted webform's search button name in the destination url ?
My site search page's url looks like this:
http://localhost/Work/buzz/Templates/pagination_GET_METHOD_TEMPLATE.php
When I click the search button, I am taken to same page $_SERVER['PHP_SELF'];.
Taken to:
http://localhost/Work/buzz/Templates/pagination_GET_METHOD_TEMPLATE.php?search=&match=fuzzy&index=crawled_links_index&limit=1&web_search_button=

NOTE the last part of the destination url:
&web_search_button=
That is the search button's name.

<button type="submit" name="web_search_button" id="web_search_button" title="search the Web">Search!</button>

What to do so destination url looks like following when using GET METHOD ?
http://localhost/Work/buzz/Templates/pagination_GET_METHOD_TEMPLATE.php?search=&match=fuzzy&index=crawled_links_index&limit=1

@rproffitt

You know the answer, ofcourse.

When you submit a form, then every form field and button gets submitted to the form. When using the GET method, each and every one of those fields (including the button) becomes part of the query string. When using the POST method, each and every one of those fields (including the button) gets submitted in the body of the HTTP request.

I'm not sure if this will work, but what happens if you remove the name property from the button? e.g. remove name="web_search_button". I'm not sure if that will work but it's just a thought.

commented: It's kind of ok for me try for it. +0

@dani

You not sure it will work!
No programmers are really not sure of a basic thing like that ? You mean, you and all the progarmmers never even tried testing a basic thing like that when using GET and finding the button name got injected in the url and lengthened the url unnecessarily ?
And yet, again how come it did not even occur to me that it will work by removing the name attribute ? I can really talk!
What has got all us programmers blind ?
Anyway, it worked. Thanks!

It’s one of those things that makes sense to work but I’ve never tried it myself because I never had a need for it.

Typically, form buttons use POST and not GET, or at least that’s been my use case.

Glad it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.