Submitting a form on a custom admin page in wordpress

wordpress plugin form submit action
how to code custom submit form in php in wordpress
how to create custom form in wordpress admin panel
wordpress get form post data
wordpress ajax form submit example
wordpress form action php file
wordpress admin-post redirect
wordpress custom plugin submit form

I created a custom page in the wordpress admin which has a simple file upload field and a submit button. I need to figure out how to submit the page to somewhere it can be processed but can't find anything on the web. Does anyone know what the 'action' needs to be on the form to get it to go to a function or another page where i can process the file?

use this code snippet:

add_action( 'admin_action_wpse10500', 'wpse10500_admin_action' );
function wpse10500_admin_action()
{
    // Do your stuff here
    wp_redirect( $_SERVER['HTTP_REFERER'] );
    exit();
}
add_action( 'admin_menu', 'wpse10500_admin_menu' );
function wpse10500_admin_menu()
{
    add_management_page( 'WPSE 10500 Test page', 'WPSE 10500 Test page', 'administrator', 'wpse10500', 'wpse10500_do_page' );
}
function wpse10500_do_page()
{
?>
    <form method="POST" action="<?php echo admin_url( 'admin.php' ); ?>">
        <input type="hidden" name="action" value="wpse10500" />
        <input type="submit" value="Do it!" />
    </form>
<?php
} 

Handling Form Submissions in WordPress with Admin-Post and , php of the plugin. If you'd like to know more about adding admin pages to your plugin, have a look at our article about creating WordPress admin  The admin goes to the Wordpress admin panel to approve the pending requests for the club. (The data is fetched from db and shown to the admin). I have done the following: for 1) I have created a application form/page using the Wordpress HTML editor. for 3) I have a javascript file (validation.js) that has the validation code.

Thanks Mr. Hunter. Couldn't credit you for the right answer.

Wrapped the form in a if(isset($_POST['submit'])) and then called my functions.

Creating Custom WordPress Administration Pages, Part 2, Creating Custom WordPress Administration Pages, Part 2 form method = "post" action="<?php echo esc_html( admin_url( 'admin-post.php' ) ); ?> function to denote where we'll be posting the options (which we'll talk about  I am developing a plugin that has a front-end form to be submitted by registered users with a community role of “Member” and then get inserted to a custom database, users with community role “Admin” cannot submit this form.

I had to change code like this to work:

add_action( 'admin_post_wpse10500', 'wpse10500_admin_action' );

Use 'get' form action within a WordPress plugin admin page , Try to use this code, <form action="http://www.mydomain.com/wp-admin/admin.​php" method="get"> <input type="hidden" name="page" value="my-plugin.php"  Caldera Forms – this lets you build the form. Caldera Forms Custom Fields – this add-on lets you save your form inputs as WordPress post types. Posts Table Pro – this plugin lets you display the information that your users submit in a flexible table layout.

I am answering this specific part of the OP's question using a different way than the accepted answer to get results:

Does anyone know what the 'action' needs to be on the form to get it to go to a function...

post to the same page- via blank form action- different actions can be taken based on the same single form.

if ( isset($_POST['custom_action']) ){
    if ( $_POST['custom_action'] == 'update'){
        if ( isset($_POST['Submit']) ) {
            //form validation and gather into a single object $valid;
            //I put this in a class, so self::update_main_config($valid);
            //otherwise you can just update_main_config($valid)
        }
        if ( isset($_POST['Submit_Default']) ) {
            //no form validation needed & defaults handled via custom wp_option, this could also be static function very easily
            //secondary action group such as self::restore_config_defaults();
        }
    }
}

Based on a custom admin page I use for one of my plugins, I conditionally set the context for what I expect to happen. My admin config page submits new values and it can restore default values... but it can also affect other modules based on user input. I am showing how to use fairly simple conditionals to create more complex submit contexts. What if the upload were a photo, and the Admin needs control to post to an arbitrary user profile- but we want to reuse the same code to allow a logged in user to post their own profile pic? This is why contexts, and this is why I think my methodology is relevant.

I am fond of re-using code and taking advantage of a single functional loop to process any single context- and again, using a single hidden form input, or potentially multiple controls based on user-or-admin events, one can alter the context using the same form and theoretically 1 or more submit buttons. I actually wanted 2 buttons to separate the actions in the mind of the submitter, so I have shown that method.

Here is the corresponding HTML

<form name="config_actions" action="" method="post">
<input type="hidden" id="custom_action" name="custom_action" value="update" />
<input type="submit" id="my_main_action" name="Submit" value="Update" />
<input type="submit" id="my_secondary_action" name="Submit_Default" value="Restore Defaults" />
</form>

Using simple javascript to conditionally set input#custom_action to a value suitable to create my context-- for sake of this example it validates when custom_action is set to "update", although in my code I use other contexts as well based on form responses.

My prior example gained -2 (!) I use $_POST['action'] which means input[name="action"] not to be confused with form[action=""] as my former code implied- so yeah that was bad. Here I am showing more clearly that I have a hidden input context manager named 'custom_action' and I have 2 submit buttons named 'Submit' and 'Submit_Default' which both effectively trigger the same form because they are both type=submit.

$_POST form request with admin-post, So when there is a form submitted to admin-post.php and there is an action value of I had more than one page with what I was working on so I done 2 different  The Settings API, added in WordPress 2.7, allows admin pages containing settings forms to be managed semi-automatically. It lets you define settings pages, sections within those pages and fields within the sections.

Handling POST Requests the WordPress Way, Get the Right File Permissions in Your WordPress Site with our This is possible by pointing all our form submissions to a specific file in the wp-admin a custom page template based on the basic page.php , hardcode a  Step 1: Create a Post Submission Form. The first thing you need to do is install and activate the WPForms plugin. Here’s a step by step guide on how to install a WordPress plugin. In order to allow your audience to submit guest posts, you’ll need to install our Post Submissions addon.

Add WordPress Admin Post Action, Creating a WordPress Admin Post action allows you to create a custom form and Step 1: Add Action in class-plugin-name-admin.php file's construct function You can add this to the Plugin settings page or to a random Plugin page that you​  After you’ve created a custom form on your website, click Save. Redirect Users after a WordPress Form Submission. After you’ve created your form, you’re ready to redirect users to another page once they submit the form. You can redirect your site visitors to two places using WPForms: To another page on your website, such as a thank you page

How to add a WordPress admin page to add data to a custom table , This tutorial shows you how to create an admin page and insert data into that Screenshot of laptop with code to add a custom WordPress admin page <input type="submit" value="submit" /> </form>. Now we get into the  You can create a form in WordPress page by following these steps- Go to  Pages -> Add New option given under your WordPress dashboard. Give the title of the page you want, like ‘Customer Details’. Now navigate to the ‘ HTML ’ tab to write HTML code.

Comments
  • If you leave the action blank it will submit to the page it's on.
  • Thanks! I figured that out a while ago...lol..should have closed the post. Had a House moment and realized how I used to do it. Wrapped the form in a if(isset($_POST['submit'])) and then called my functions.
  • No problem, glad you figured it out
  • Thank you! Been chasing this all morning.
  • I know this is an old comment, but how do you show the results of whatever you did in your action - wpse10500_admin_action
  • I'd appreciate some context on this. Of course, you're adding a management page link to Tools and creating that page with wpse10500_do_page(), containing a form. But the added action "admin_action_wpse10500" merits further explanation... is this really "admin_actions_*" wherein * = the "value" of the "hidden" form "input"? ++ EDIT: Looks like I'm right about that.