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

  • The action on the form needs to be the the admin url and then you need a hidden form element with name="action" and value="volunteer". Nov 16, 2016 at 11:31

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">

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
  • Thanks, I tried to do that from the Dashboard, following the form->edit menu. But if I try to insert a hidden field there is no way (I didn't find it) to set "id" and "value" attributes. I also tried to set an HTML Content to "<input type="hidden" name="action" value="volontari">". No result
    – marcello
    Nov 16, 2016 at 12:06
  • It looks like your using Gravity forms - might be worth a look at the docs to see if you can hook into the form and add/update the necessary action(s). Nov 16, 2016 at 12:13
  • Thanks "Gravity Forms" was the way. Using his hooks I solved
    – marcello
    Nov 16, 2016 at 13:14

Just checked the code in admin-post.php. Apparently when the user is authenticated the hook admin_post_ACTIONNAME is called.

BUT for an unauthorized request the hook admin_post_nopriv_register_ACTIONAME is called. So I thought everything worked fine on the website. Until an actual client of my practice informed me the register forms weren't operational at all.


SO! I though I share this information for people who are trying to debug this damn hook.

  • So, you always have to register both? May 11, 2020 at 17:35
  • I think so. One for authenticated users and one for guests. Depending on the needs of your form of course.
    – Floris
    May 12, 2020 at 13:42
  • Oh man, I was wondering why my hook was not firing and then I read your answer. Thanks a bunch!
    – Marko
    Oct 19, 2021 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.