Open NebriBlackwing opened 8 years ago
Might I suggest doing wp_die(var_dump($_POST));
inside of the add_foobar() function before your redirect code just to make sure your function is, in fact, being called?
You might need to try adding your action into your Plugin_Employee_Directory_Admin() __construct method like this:
add_action('admin_post_nopriv_add_foobar',array(&$this,'add_foobar'));
Your hook name is wrong you try to use 'admin_post_add_foorbar' but should be 'admin_post_add_foobar' ( foorbar ).
LOL good catch!
Hello,
I'm trying to create a plugin for a client that will accept a form entry to populate a custom database table. I'm having difficulty using the adminpost(action) functionality in wordpress with this the plugin-boilerplate.
I referenced this: https://codex.wordpress.org/Plugin_API/Action_Reference/admin_post_(action)
to come up with the following in my class-plugin-name.php
`/* * Register all of the hooks related to the admin area functionality * of the plugin. * @since 1.0.0 * @access private */ private function define_admin_hooks() {
And then inside my plugin-name-admin.php I've declared the following public function:
public function add_foobar() { wp_redirect( home_url() ); exit; }
Inside the partial view I have:
<form id="employeeForm" action="<?php echo admin_url('admin-post.php'); ?>" method="post"> <input type="hidden" name="action" value="add_foobar">
Now when I submit the form itself, I do get sent to /wp-admin/admin-post.php, but it just stays a white screen. I never get the redirect back to my home url as expected. This plugin will have several get and post requests that I'll need to create to do my own processing. Would greatly appreciate some help as I'm either not understanding something, or am missing something in my implementation.