admin管理员组文章数量:1122832
I have written a plugin that interfaces with a third-party mailing API. I have created a settings page for my plugin that includes two buttons:
- a submit button created with
submit_button()
which saves the form - a "test settings" button that should use the current values from the form without saving them
This is what I currently have:
echo '<form method="post" action="options.php">';
settings_fields('myplugin_settings');
do_settings_sections('myplugin');
echo '<p>';
submit_button('Test Settings', '', 'test', false);
echo ' ';
submit_button(null, 'primary', 'submit', false);
echo '</p></form>';
This produces two buttons, as expected:
However, I don't know how to override the action for the "test settings" button. Is there a hook for this? I can't find any documentation for this.
I have written a plugin that interfaces with a third-party mailing API. I have created a settings page for my plugin that includes two buttons:
- a submit button created with
submit_button()
which saves the form - a "test settings" button that should use the current values from the form without saving them
This is what I currently have:
echo '<form method="post" action="options.php">';
settings_fields('myplugin_settings');
do_settings_sections('myplugin');
echo '<p>';
submit_button('Test Settings', '', 'test', false);
echo ' ';
submit_button(null, 'primary', 'submit', false);
echo '</p></form>';
This produces two buttons, as expected:
However, I don't know how to override the action for the "test settings" button. Is there a hook for this? I can't find any documentation for this.
Share Improve this question asked Jul 19, 2016 at 1:10 George EdisonGeorge Edison 4251 gold badge5 silver badges9 bronze badges 3 |1 Answer
Reset to default 0It's not clear to me what the "test" button is for, which I guess could make a difference, but, in general, I have found that to make two buttons work independently on the same options page, the easiest thing is to place them within two separately defined forms, even if the two buttons are going to be placed side by side.
The simplest method is just to create a "mini-form" for the "special" button, and, if need be use a little CSS to place the second button before or above, etc., the "primary" button. So, depending on what else is going on where you are placing the button, if you really need and want the test button to appear first, you could float it to the left. Also, you should note that, though you can style the button produced by "submit_button" using optional parameters ("type," "attribute" - see Codex), you aren't obligated to use it with the Settings API: You can produce the same button, and then add whatever selectors or element-styles, with the regular old button html that submit_button() produces.
So, mainly to illustrate:
echo '<form method="post" action="options.php">';
settings_fields('myplugin_settings');
do_settings_sections('myplugin');
echo '<p>';
submit_button(null, 'primary', 'submit', false);
echo '</form>';
echo '
<form method="post" name="test-button">
<span id="test-button">
<input id="test-settings" type="submit" value="Test Settings" class="button" >
</span>
</form>
';
本文标签: plugin developmentHow to add a secondary button to a settings page with a custom action
版权声明:本文标题:plugin development - How to add a secondary button to a settings page with a custom action? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288891a1928189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
formaction
attributes on the buttons. – fuxia ♦ Commented Jul 19, 2016 at 2:06