Support

Account

Home Forums Front-end Issues Front end post submit hook

Solving

Front end post submit hook

  • Hi Elliot,

    What’s the hook for the Submit button of a front end post field group? What I’m trying to do is send a thank you mail as soon as someone posts a post with a specific field group.

    I did try the hook add_action('acf/save_post', 'sendMail', 20); But that did not work.

    Thanks!

  • Hi @LeffDesign

    The ‘acf/save_post’ action will be fired for both the front and back end forms.

    There is also a ‘acf/pre_save_post’ filter fired on the front end form.

    Check out the docs regarding acf_form to learn more.

    Thanks
    E

  • Alright, thanks. But must I place this function in the same post template file? Or can I put it in the functions.php and set a specific form for this function?

    So the mail will only be send when form X is submitted.

  • Hi @LeffDesign

    Please place this action in the functions.php file. But you can include it in the page template if you wish (I think it will need to be defined above the acf_form_head) function

    Thanks
    E

  • Alright, thanks. Sorry, it’s not yet clear yet. Let’s say I would put the next function in functions.php. Then it would send a mail every time a ACF form is saved, right?

    <?php function sendMail(){
    $to = '[email protected]';
    $subject = 'New mail';
    $headers = 'From: Themailer <[email protected]';
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $message = '<html><p>Thank you!</p></html>';
    mail($to, $subject, $message, $headers);
     }
     add_action('acf/pre_save_post', 'sendMail', 20); ?>

    How would I link this to a specific ACF form? Thanks!

  • Hi @LeffDesign

    No, this is not correct.
    The ‘acf/pre_save_post’ is a filter, not an action. You will need to connect this to a custom function which accepts and returns the $post_id parameter. Before returning the $post_id, you can then fire the sendMail() function.

    Please read the doc article on creating a post via the acf_form to understand how this filter works:
    http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/

    Thanks
    E

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Front end post submit hook’ is closed to new replies.