vladislavvladislav vladislavvladislav - 6 months ago 9
HTML Question

Executing form with JS on tag <a>

I found similar questions here, but not what i'm looking for.

I want to send form, when clicking on html tag

<a>
, with java script. My problem is that I don't know where I put the name, so I can use php isset function later.

This is what I did, but it's not working:

<?php
if (isset($_POST['test'])) {
echo "Test Kappa 123";
}
?>

<form method="post" action="<?=$site_link?>user/<?=$username?>" id="form_options">
<a href="javascript:void();" name="test" onclick="document.getElementById('form_options').submit();"> Radnom text </a>
</form>

Answer

You can place the value in a hidden input field like so:

<?php
if (isset($_POST['test'])) {
    echo "Test Kappa 123";
}
?>

<form method="post" action="<?=$site_link?>user/<?=$username?>" id="form_options">
    <input type="hidden" name="test" value="test value" />
    <a href="#" onclick="document.getElementById('form_options').submit(); return false"> Radnom text </a>
</form>

Note: I made a number of changes from your code.

Comments