How to pass POST parameters in a URL?

Mawg says reinstate Monica picture Mawg says reinstate Monica · Jun 2, 2011 · Viewed 239k times · Source

Basically, I think that I can't, but would be very happy to be proven wrong.

I am generating an HTML menu dynamically in PHP, adding one item for each current user, so that I get something like <a href="process_user.php?user=<user>>, but I have a preference for POST over GET.

Is there any way to pass the info as a POST parameter, rather than GET from a clickable HREF link?


Update: sorry, I am not allowed to use JS - I shoulda said, my bad


Update to the update: it looks like @Rob is on to somethign with "You could use a button instead of an anchor and just style the button to look like a link. That way you could have your values in hidden fields inside the same form to be sent via POST"

Answer

Petah picture Petah · Jun 2, 2011

You could use a form styled as a link, no JavaScript required:

<form action="/do/stuff.php" method="post">
    <input type="hidden" name="user_id" value="123" />
    <button>Go to user 123</button>
</form>

CSS:

button {
    border: 0;
    padding: 0;
    display: inline;
    background: none;
    text-decoration: underline;
    color: blue;
}
button:hover {
    cursor: pointer;
}

See: http://jsfiddle.net/SkQRN/