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>
答案 0 :(得分:1)
您可以将值放在hidden
输入字段中,如下所示:
<?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>
注意:我从您的代码中做了一些更改。
答案 1 :(得分:1)
表单仅在<button>
,<input>
和<textarea>
中提交值,而不是<a>
。你应该把这个链接变成一个按钮,然后你甚至不必使用javascript。
像这样:
<form method="post" action="<?=$site_link?>user/<?=$username?>" id="form_options">
<button name="test" type="submit" value="test">Radnom text</button>
</form>
如果你不希望它看起来像一个按钮。您可以使用此css删除背景和边框:
<style>
button {
background:none;
border:none;
}
</style>