Submit HTML form using GET or POST without the ‘Submit’ button

Whenever you submit a form using the submit button, the value of the submit button is also sent.

For example, this form:

<form id="myForm" method="get" action="http://www.your-site-name.com/page.php">
 <input type="text" name="value1" value="foo">
 <input type="text" name="value2" value="bar">
 <input type="submit" name="submit" value="Submit">
</submit>

Will open a page with the following URL:

http://www.your-site-name.com/page.php?value1=foo&value2=bar&submit=Submit

The best way to prevent the submit variable from showing is to not transmit the form using the submit button, but instead to use a bit of JavaScript on a normal button:

<form id="myForm" method="get" action="http://www.your-site-name.com/page.php">
 <input type="text" name="value1" value="foo">
 <input type="text" name="value2" value="bar">
 <input type="button" name="submit" value="Submit" onClick="document.getElementById('myForm').submit();">
</submit>

Which will yield a submitted form with the following URL:

http://www.your-site-name.com/page.php?value1=foo&value2=bar

Voila.

Leave a Reply

Your email address will not be published. Required fields are marked *