0

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!

4
  • Your question isn't very clear. Putting parameters in the URL is a common thing to do, and accessing them with $_GET is commonplace. Are you asking about something different from that? Commented Jul 30, 2013 at 15:44
  • Well I was wondering if you can still retrieve the data from the URL as an alternative to using a form. Commented Jul 30, 2013 at 15:55
  • What else did you think URL parameters were for? Commented Jul 30, 2013 at 16:01
  • I didn't know if a form did that or what, but thank you. Commented Jul 30, 2013 at 16:10

2 Answers 2

5

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>
Sign up to request clarification or add additional context in comments.

2 Comments

That make's it a GET request not a POST request. Update this answer to explain the difference?
I think he's just using the word post generically, to mean submit.
0

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".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.