user1759682 user1759682 - 1 month ago 4
HTML Question

Why is the submit button value passed when using the GET method in HTML?

I am using the the "GET" method in a form on my website. For some reason it is passing the value of the submit button to the url. Why is this happening? What am I doing wrong?

Form:

<form method="GET" action="searcht1.php">
<input type="text" name="search"/>
<input type="submit" name="submit">
</form>


Url:

searcht1.php?search=colin+pacelli&submit=Submit

Answer

It's supposed to happen. If you don't want that, do not define name attribute on the button. You probably want value instead, to show the user what the button is for.

Also, this question has nothing to do with PHP; it is purely about HTML semantics.

Comments