[英]Submit a form using a link and pass a post variable
Hi I want to use an anchor tag to submit a form. 嗨,我想使用锚标签提交表单。 However the only problem is that my form had an input button (now replaced by anchor tag) that passed a post variable so that in my php script I could check to see if that post variable was set.
但是,唯一的问题是我的表单有一个输入按钮(现在已由定位标记代替)传递了一个post变量,以便在我的php脚本中可以检查该post变量是否已设置。 How can I achieve this same technique using an achor tag?
如何使用achor标签实现相同的技术? Here is what I have tried:
这是我尝试过的:
FORM USING AN INPUT BUTTON (old): 使用输入按钮的形式(旧):
<form method="post" action="delete.php" onsubmit="return confirm('Do you really want to delete?');">
<input class="delbtn" name="deleteuser" type="submit" value="Delete"/>
</form>
FORM USING ANCHOR TAG INSTEAD OF INPUT SUBMIT (new): 使用锚标签代替输入提交的表格(新):
<form id="delform" method="post" action="delete.php" onsubmit="return confirm('Do you really want to delete?');">
<a href="javascript:void();" onclick="document.getElementById('delform').onsubmit();" class="delbtn" >Delete</a>
</form>
In my php class I am checking to see if the form was submitted using the post variable from the input button ("deleteuser"). 在我的php类中,我正在检查是否使用输入按钮(“ deleteuser”)中的post变量提交了表单。 However how can I do the same using an anchor tag?
但是,如何使用定位标记执行相同的操作?
You've almost got it in your second try, just call .submit() instead of onsubmit(). 在第二次尝试中您几乎已经掌握了它,只需调用.submit()而不是onsubmit()。
<form id="delform" method="post" action="delete.php" onsubmit="if( confirm('Do you really want to delete?')) {this.submit();}">
<a href="javascript:void();" onclick="document.getElementById('delform').onsubmit();" class="delbtn" >Delete</a>
<input type="hidden" name="action" value="deleteuser" />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.