admin管理员组文章数量:1386662
I'm working on my settings page, I want to add two different buttons to the form and do something different depending which the user clicked.
The documentation states I can create two buttons like this:
submit_button('Submit', 'primary large', 'primary', false);
submit_button( 'Delete', 'delete', 'delete', false );
However I don't understand how to differenciate when the user clicked each one, it seems that no matter which button clicked the form is submitted the same.
How can I do something different depending what button the user clicks?
I'm working on my settings page, I want to add two different buttons to the form and do something different depending which the user clicked.
The documentation states I can create two buttons like this:
submit_button('Submit', 'primary large', 'primary', false);
submit_button( 'Delete', 'delete', 'delete', false );
However I don't understand how to differenciate when the user clicked each one, it seems that no matter which button clicked the form is submitted the same.
How can I do something different depending what button the user clicks?
Share Improve this question asked Jan 22, 2015 at 15:46 Lisandro VaccaroLisandro Vaccaro 9954 gold badges12 silver badges28 bronze badges1 Answer
Reset to default 2The submit_button()
function is a wrapper for get_submit_button()
. Now that function has multiple arguments, but the most interesting for your actual problem is the 3rd argument name
. It sets the HTML name
attribute.
<form action="">
<input ... etc.
<button type="submit" name="choice-a">
</form>
Now everytime you process your form with an empty action
attribute, you will point to the current request http://example/wp-admin/example.php
. There you will be able to fetch your arguments via the super globals $_POST
or $_REQUEST
(which simplified is mostly a combination of $_GET
and $_POST
).
Then just inspect the array and do whatever you need/want to do.
本文标签: formsHow to know what submit button the user clicked
版权声明:本文标题:forms - How to know what submit button the user clicked? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744567603a2613146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论