WordPress plugin custom admin page – form result shows on blank page

  php, wordpress, wordpress-plugin-creation

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">

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…

Thanks in advance!

Source: Ask PHP