Reputation: 1
I have some data that needs to be posted without the site's pre-defined style for forms getting in the way. Can I use an href to post data without the use of the form, and then retrieve it with PHP?
HTML Example:
<a href="rcon.php?action=roomForward&roomId=7" />
PHP Example:
<?php
[Function Stuff for roomForward Here..]
$core->Mus('senduser', '$_GET["roomid"]', ' . USER_ID . ');
?>
My code isn't perfect but it's just supposed to make sense for now!
Upvotes: 0
Views: 16820
Reputation: 781004
Yes. The whole point of allowing parameters in the URL is so that they can be retrieved by server scripts. They have nothing to do with forms, except that they can also be set by a form if it uses method="get"
.
Upvotes: 0
Reputation: 57719
No, the href produces strictly GET
requests.
You can fake it by having an onclick handler on a link that submits a form instead.
<script>
function post(event) {
event.preventDefault();
document.getElementById("my_form").submit();
}
</script>
<form action="action.php" method="post" id="my_form" style="display: none;">
<input type="hidden" name="key" value="val" />
</form>
<a href="#" onclick="post()">click me!</a>
Upvotes: 5