Is the only way of passing POST parameters in HTML through a form?

In HTML, you can send data from one page to another using a GET request in a couple of ways:


<form action="somepage.php" method="get">
  <input type="hidden" name="data" value="1" />
  <input type="submit" value="Submit">

With a POST request though, I've only seen data being sent through form elements like this:

<form action="somepage.php" method="post">
  <input type="hidden" name="data" value="1" />
  <input type="submit" value="Submit">

If I only have one parameter I want to send to another page using POST, is there an easier way than wrapping it in a form?


There are only two ways to POST from a browser - a form, or an Ajax request.

Using HTML only, a form is the only way to generate a POST request. You can use server side scripting / Javascript to generate POST requests in other ways, but no other ways to do with plain HTML only.

As you've already discovered, there are exactly two ways to transmit data over the http protocol: GET or POST. There is also a third type of HTTP message called HEAD, but that's really only used to get the meta data around a resource without downloading it and isn't widely implemented.

Obviously both GET and POST are easily accessible through the use of a <form> tag. The GET is also easily accessible by manually adding query parameters to the URL in the form of name-value pairs (foo.html?a=1&b=2).

The beauty and complexity of the POST, however, is that the name-value pairs are communicated from the browser to the web server enclosed within the HTTP request header which is not as easily accessible. The only way to accomplish the POST without using a <form> tag is to manually alter the HTTP request header and add the name-value pairs in yourself.

Also keep in mind that an HTTP server doesn't intrinsically know whether a request (GET or POST) came from a main browser window or an AJAX call. Regardless, the web server will read the request, will decipher if it's a GET or POST request, look for name-value pairs as appropriate, and generate a response.

If you'd like additional detail on how to properly format a POST request you can go to or perhaps The definitive resource is always the W3C, but sometimes the RFCs can be terribly confusing for us mere mortals to read.

In HTML only it's with a form.

But you can do it if you play with your server side. Here is a good article that show you how to manipulate the Get to Change it to Post via PHP. This will require you to play with fsockopen... This way to do it will use your parameter ?id=1&param=2 ... and will create a POST request on the server side. You can make it generic, once it setups it will works, but it's a little work to setup everything first.

You can of course always do a GET to a page which contains server-side (or AJAX) logic which will create a POST request (e.g. GET / Very messy of course, but there can be cases where such a work-around could maybe be useful.

Need Your Help

Passing ByteArray from flash (as3) to AMFPHP (2.0.1)

php json actionscript-3 bytearray amfphp

i have a problem passing ByteArray from flash (as3) to amfphp to save an image.

android send email automatically

android email send

I want to send email automatically (without user interface). When i execute the application i have no error but when i check my inbox i find no email