Reputation: 331
I'm a newbie to wordpress plugin development and from the wordpress development tutorials and articles I've come to understand that in order to add a kind of a listener to an action, hooks must be used. So can anyone tell me how to do such thing on form submit? Suppose there's another plugin handling the form creation if it makes any difference.
Upvotes: 0
Views: 8308
Reputation: 108
If the plugin that is generating the form has created any hooks that can be hooked in to you should be able to do that and add your own custom code.
Alternatively I think you can use the admin post hook. Basically you do something like the following:
add_action( 'admin_post_add_foobar', 'prefix_admin_add_foobar' );
function prefix_admin_add_foobar() {
// Handle request then generate response using echo or leaving PHP and using HTML
}
So the above goes into your functions.php file, and whenever your form has an action parameter of 'add_foorbar', the code within the 'prefix_admin_add_footbar' function is called. This code is taken directly from https://codex.wordpress.org/Plugin_API/Action_Reference/admin_post_(action) which should provide more info.
Upvotes: 2