我正在编写一个插件,它使用一个表单将一些数据传递给自己。
有没有什么方法可以做到这一点“WordPress方式”?
示例表单代码(在“工具”下添加的自定义子菜单页上):
<form action="<?php echo get_admin_url() . \'admin-post.php\'; ?>" method="post">
<input name="some_input" type="text">
<input name="other_input" type="text">
</form>
然后在插件的逻辑方面:function my_process_form_data() {
// Process the form data here and return the results
}
add_action( \'admin_post\', \'my_process_form_data\' );
现在,我已经处理了表单并获得了结果数据(存储为一个较大的数组),将该数据返回到我创建的自定义子菜单页的最佳方式是什么?我知道有几种选择:
我可以直接发布到页面,而不是发布到“admin post.php”。但这会导致一些混乱的代码和条件(即,如果是结果,请加载此,否则请加载此。理想情况下,模板和逻辑应保持独立。