How to prevent a form with GET method from sending the value of the submit button?
I have a simple form:
<form action="/search" method="get"> <input type="text" name="q" value=""> <input type="submit" name="search" value="search"> </form>
When submitting the url becomes `/search?q=Loremipsum&search=search
I really don't want that last bit, this seems pretty common problem and think it could be solved without js, but I realized that even google.com has this problem when you click on the search button. (maybe they don't care much about ugly urls?)
I see in Stack overflow the search is ?q= but they don't have a submit button.
You can omit name attribute in the final input like this:
<form action="/search" method="get"> <input type="text" name="q" value=""> <input type="submit" value="search"> </form>
Should do the trick. Keeping value attribute allows you to manipulate what text is displayed on the button.
For the record, you can also omit the submit button if you like, and the form will submit when you press return after typing your search term. (This is how the Stack Overflow search box works).