php - WordPress plugin custom admin page - form result shows on blank page
Get the solution ↓↓↓I am currently writing a WordPress plugin with the wppb wireframe. 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.
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? 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
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?
Thanks in advance!
Answer
Solution:
As said by Klaassiek, the codex has the right answer written in it.
Here is his comment:
You should indeed use wordpress’s ajax functionality for that. Plus, you will have to write a javascript function that does the ajax call and displays the result when the call is finished. Here is the documentation: codex.wordpress.org/AJAX_in_Plugins
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: fastcgi sent in stderr: "primary script unknown" while reading response header from upstream
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.