Is it possibe to use the POST method using a link instead of a form. For example something along these lines:
<?php
function testLink() {
$_POST['url'] = "YOYOYO";
}
?>
<a href='test2.php' onClick='testLink();'>yoyo</a>
Is it possibe to use the POST method using a link instead of a form. For example something along these lines:
<?php
function testLink() {
$_POST['url'] = "YOYOYO";
}
?>
<a href='test2.php' onClick='testLink();'>yoyo</a>
It’s possible with JavaScript, but not like that with PHP. PHP code is executed before the webpage is sent to the browser and isn’t present in the output, so a link can’t run a PHP function on the browser.
What you’d need to do to accomplish this is create a form with its method set to POST, make your “url” variable a hidden form field, and use JavaScript to submit that form on clicking the link.
No it is not possible to post without having any form in the page as far as i know. But if you have a form in the page but you want to submit the form without a submit button (i mean if you want to submit the form vial a link click) then you can use javascript to submit the form.
If there anyone shows me that is possible, it would be helpful to me too.
<script>
function submitForm() {
// Can do some validation here if needed
document.getElementById('sample_form').submit();
return true;
}
</script>
<form method="POST" action="test.php" id="sample_form">
<!-- form bits here -->
</form>
<a href="javascript:void(0);" onclick="submitForm();">Submit</a>
The link can be anywhere on the page … it doesn’t have to be ‘within’ the form
Hope this helps … it’s from memory so it may not be completely correct
Yes of course it can be submitted with the link located anywhere in the page, but at least he should have a form tag in the page.