简体   繁体   English

WordPress 插件自定义管理页面 - 表单结果显示在空白页面上

[英]WordPress plugin custom admin page - form result shows on blank page

I am currently writing a WordPress plugin with the wppb wireframe.我目前正在编写一个带有 wppb 线框的 WordPress 插件。 For the first time I need a custom settings page.我第一次需要自定义设置页面。 I implemented it and also created a custom action hook to fire a function that gets some data as a result.我实现了它,还创建了一个自定义操作挂钩来触发 function,从而获得一些数据。

For now, I want to show this result in the admin page.现在,我想在管理页面中显示这个结果。 But when I click on the button, the result is shown on a blank page rather than on the admin page.但是当我单击按钮时,结果显示在空白页面而不是管理页面上。

How can tell my form and function to show the data in the admin dashboard and not on a blank page?如何告诉我的表单和 function 在管理仪表板中而不是在空白页上显示数据? I didn't find any help over google...我没有通过谷歌找到任何帮助......

What I have so far:到目前为止我所拥有的:

On the admin settings page在管理设置页面

<form action="http://myurl.com/wp-admin/admin-post.php" method="post">
  <input type="hidden" name="action" value="search_api">
  <input type="hidden" name="data" value="test">
  <input type="submit" value="Submit">
</form>

The action hook动作挂钩

$this->loader->add_action('admin_post_search_api', $plugin_admin, 'admin_search_api');

The function function

public function admin_search_api() {
  echo $_POST['data'];
}

So, when I submit the form, a new page is loading and there is the expected result.因此,当我提交表单时,正在加载一个新页面并且有预期的结果。 But how can I frame it into the custom settings page?但是如何将其框入自定义设置页面? I am clueless...我一无所知...

So for clarification: I want to load the result of the form on the same page as the form.所以为了澄清:我想将表单的结果加载到与表单相同的页面上。 I am not really familiar with the wp-ajax, but might this be the answer?我对 wp-ajax 不是很熟悉,但这可能是答案吗?

Thanks in advance!提前致谢!

As said by Klaassiek, the codex has the right answer written in it.正如 Klaassiek 所说,法典中写有正确的答案。

Here is his comment:这是他的评论:

You should indeed use wordpress's ajax functionality for that.您确实应该为此使用 wordpress 的 ajax 功能。 Plus, you will have to write a javascript function that does the ajax call and displays the result when the call is finished.另外,您必须编写一个 javascript function 来执行 ajax 调用并在调用完成时显示结果。 Here is the documentation: codex.wordpress.org/AJAX_in_Plugins这是文档:codex.wordpress.org/AJAX_in_Plugins

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM