• Resolved Sandra Romano

    (@sandraromano)


    Hi!

    I have just purchased the Pro version of the plugin, triying to enable the edition of already published posts by an AF form. But I am unable to populate automatically the required fields to create the notification email.

    Our website is a journal, to which authors can submit papers, creating a new custom post type named “Articles” with all their data (title, name of the Author, email, etc.). I have already created a form that accomplish this perfectly.

    Now I need a new form to add to any of the already submitted “articles” a new field (a revision), and that sends also a notification email to the article’s author with the text revision. I would like to select the email for the recipient, the name of the Author, etc., that are all already saved in the post. There’s no need to create parallel fields for these already saved data, that could be populated for the form.

    How can I achieve this? Any help?

    Thanks for any help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi, Sandra! If I’m understanding you correctly this should be doable. Let’s see if I can offer some assistance.

    I would start by having two different ACF field groups, one for all your Articles data (like you already have) and one with only the revision field. Both of these point toward your Articles post type and each one also point to their respective form.

    Next you should set up the revision form for post editing and also add a email notification. The tricky part is of course to get the previous post data into the email notification. This isn’t built-in but can be achieved very easily with a tiny bit of code. Add a dummy recipient when setting up your email and the use something like this to override it:

    
    function change_revision_notification_recipient() {
      // Find ID of article being edited
      $args = AF()->submission['args'];
      $post_id = $args['post'];
    
      // Get name and email of article author
      $name = get_field( 'NAME_FIELD_NAME', $post_id );
      $email = get_field( 'EMAIL_FIELD_NAME', $post_id );
    
      // Return new recipient with name and email from existing article
      return sprintf( '%s <%s>', $name, $email );
    }
    add_filter( 'af/form/email/recipient/key=FORM_KEY', 'change_revision_notification_recipient', 10, 0 );
    

    The reason this should work is when you are doing post editing you need to set the “post” argument to a post ID. This code simply uses the post ID to lookup name and email from the existing article and then uses that to set the recipient of the email.

    Also, because you are a Pro user you can get priority support. Would recommend reaching out through here: https://hookturn.io/contact/ the next time you need help!

    Hope this helps! 🙂

    Thread Starter Sandra Romano

    (@sandraromano)

    Hi Fabian! Thanks a lot for your answer, but I am going to write directly to the support page, then. I’m afraid I am not able to understand your code…
    Thanks again. Greetings.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Editing posts’ is closed to new replies.