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 开发者_如何学JAVAlast 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?)
search?hl=en&source=hp&q=Loremipsum&
btnG=Google+Search
&aq=f&..
Is there a way to prevent the value of the submit button to be excluded without javascript?
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).
精彩评论