admin_post hook not called

I have good experience in other CMS. but I’m very new in WordPress.
My goal is to intercept POST values in some of the form of a pre-existent site.
Following documentation I’ve done the following steps:

  • I had a look on the page source, finding that the form action:

< form method=’post’ enctype=”multipart/form-data” id=’gform_4′
action=’/volunteer/’>

  • in theme folder I modified function.php adding the code:

add_action( ‘admin_post_nopriv_/volunteer/’, ‘send_contact_to_civicrm’);

add_action( ‘admin_post_/volunteer/’, ‘send_contact_to_civicrm’ );

  • finally in the same .php file I added the function

function send_contact_to_civicrm() { … };

But my function is not executed.
I also tried to modify the action name in ‘admin_post_nopriv_volunteer’ but with no result.

Where am I doing wrong?
Thanks

2 Answers
2

Modify your form to include:

<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
    <input type="hidden" name="action" value="volunteer">
    ...
</form>

and add an action to run your function:

add_action( 'admin_post_volunteer', 'send_contact_to_civicrm' );
add_action( 'admin_post_nopriv_volunteer', 'send_contact_to_civicrm' );

function send_contact_to_civicrm() {
   // stuff here
}

Leave a Comment