Reputation: 39
So there's this hyperlink - it's happy being a hyperlink - it does not want to change to a button or a form element - it wants to stay a link!
But it would really help me if I could submit it via GET or POST (something which I switch on my pages due to design criteria). Is there ANY way that I can do this
thanks Giles
Upvotes: 3
Views: 7611
Reputation: 1301
As you do not want to go for form elements, there is no need of using POST method. Simply, what you can do is:
<a href="page_location?foo=bar">Link</a>
And in the page_location page,
<?php
$foo = $_GET['foo']; //here, assigns $foo = bar
// required actions
?>
Hope you get the solution! :)
Upvotes: 1
Reputation: 76736
You're in luck... clicking a hyperlink already does a GET request.
If you want to add query parameters, append them to the query string like so:
<a href="/my/page/foo.php?onions=no&pickles=yes">link text</a>
Upvotes: 4
Reputation: 17516
I'll assume you're not really using the link as a link... that you want to submit a form with it. You'll want to keep the link inside the form you want to submit, and you can do this (jQuery):
$('#link').parents('form').attr('method', 'GET').submit();
or
$('#link').parents('form').attr('method', 'POST').submit();
Upvotes: 0
Reputation: 70701
Assuming you already have a form that you want to submit, you can use JavaScript to make the link submit the form:
<form id="myform">
...
</form>
<a href="#" onclick="document.getElementById('myform').submit();">Submit</a>
Upvotes: 3