Problems with making a plugin and understanding how to exit after form data posted


This is a pretty basic issue I’m having. I’m new to the wordpress framework and I’m having a hard time understanding how things interact.

I’ve setup an admin page with a table. In that table is a form link to edit or delete the row. It isn’t clear to me how to exit processing the form data properly, or direct to other admin pages.

For example this is the post callback handling two cases. One I’d like to load a form page from, and the other I would like to post admin_notice results to the default admin page.

public function process_form_action() {

    $action = $this->current_action();
    switch ($action) {

        case 'edit':
            // want to load form from admin/edit.php and display it while passing the post data and preloading the form
            // unclear how to do this properly
            // if I redirect with hooks I get the unauthorized message
            // if I include the html I don't get any of the WP framework, just the html.

        case 'delete':
            $this->delete_record($_GET);  // routine to handle database
            // do nothing or something else


My problem is in the first case I would like to present a new HTML form and preload with the selected data. I wanted to do this either using a different html template, or just redirect to a php file that handles the form/database. How is this type of thing done in wordpress?

Secondly the delete action updates the database then reloads the default page and it works ok. I would prefer to post an admin_notice and refresh the admin default page with that notice. Is a wp_redirect a standard way of doing this?


Edit: to be clear this is a method inside a class that has been setup to handle admin_post data add_action('admin_post_process_form_action', array($this->Some_Class, 'process_form_action'));

It all works fine up until I exit where would like to either load a different page like edit.php or post and admin_notice of success and refresh the current page.

user6972 3 months 0 Answers 8 views 0

Leave an answer