Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting a form on a custom admin page in wordpress

Tags:

php

wordpress

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?

like image 451
Wally Kolcz Avatar asked Jan 30 '14 13:01

Wally Kolcz


People also ask

Where do WordPress form submissions go?

All your form entries (leads) are stored in your WordPress database and are easily accessible from inside your WordPress dashboard.


2 Answers

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
} 
like image 181
Mahdi Majidzadeh Avatar answered Oct 13 '22 23:10

Mahdi Majidzadeh


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.

like image 4
Wally Kolcz Avatar answered Oct 13 '22 22:10

Wally Kolcz