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!

    • Elliot

    • January 7, 2014 at 1:27 pm

    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.

    • Elliot

    • January 8, 2014 at 10:24 am

    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@email.com';
    $subject = 'New mail';
    $headers = 'From: Themailer <email@email.com';
    $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!

    • Elliot

    • January 9, 2014 at 10:08 am

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.