PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Display Other Function Results with Custom Merge Tag

  1. I want to create a custom merge tag that will display the query results from another plugin.

    I am looking for a little more insight than what the Docs can provide here (http://www.gravityhelp.com/documentation/page/Gform_custom_merge_tags)

    Basically, the other plugin lists favorite posts of the user with the wpfp_list_most_favorited function. How can I create a merge tag that will call this function and insert the results into a Gravity Forms notification if the form is embedded on a page with the plugin's results?

    Posted 12 years ago on Tuesday August 7, 2012 | Permalink
  2. You actually want to use the gform_replace_merge_tag filter. (http://www.gravityhelp.com/documentation/page/Gform_replace_merge_tags)
    The following snippet should point you in the right direction. See NOTES section in the snippet.

    add_filter('gform_replace_merge_tags', 'replace_download_link', 10, 7);
    function replace_download_link($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) {
    
        //NOTE: this will be the merge tag you enter in the notification text
        $custom_merge_tag = '{download_link}';
    
        if(strpos($text, $custom_merge_tag) === false)
            return $text;
    
        //NOTE: replace gform_get_meta() with the function that will return the HTML to be displayed.
        $download_link = gform_get_meta($entry['id'], 'gfmergedoc_download_link');
    
        $text = str_replace($custom_merge_tag, $download_link, $text);
    
        return $text;
    }
    Posted 12 years ago on Tuesday August 7, 2012 | Permalink
  3. Thanks for the quick response Alex. I am super close, however, I cannot get the function to output the HTML into the notification email. I basically replaced the gform_get_meta with a function wpfp_list_favorite_posts.

    I then inserted {download_link} into the notification section but it's not showing up in the notificaiton email. Is there anything else I need to add?

    add_filter('gform_replace_merge_tags', 'replace_download_link', 10, 7);
    function replace_download_link($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) {
    
        //NOTE: this will be the merge tag you enter in the notification text
        $custom_merge_tag = '{download_link}';
    
        if(strpos($text, $custom_merge_tag) === false)
            return $text;
    
        //NOTE: replace gform_get_meta() with the function that will return the HTML to be displayed.
        $download_link = wpfp_list_favorite_posts();
    
        $text = str_replace($custom_merge_tag, $download_link, $text);
    
        return $text;
    }
    Posted 12 years ago on Tuesday August 7, 2012 | Permalink
  4. Alex- have you had a chance to look at this? It's been about a week now.

    Posted 12 years ago on Tuesday August 14, 2012 | Permalink
  5. I am not familiar with the wpfg_list_favorite_posts(), but I am suspecting it does not return the HTML string, but prints it to the screen. Try the following and let me know if that works for you:

    add_filter('gform_replace_merge_tags', 'replace_download_link', 10, 7);
    function replace_download_link($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) {
    
        //NOTE: this will be the merge tag you enter in the notification text
        $custom_merge_tag = '{download_link}';
    
        if(strpos($text, $custom_merge_tag) === false)
            return $text;
    
        ob_start();
        wpfp_list_favorite_posts();
        $download_link = ob_get_flush();
        $text = str_replace($custom_merge_tag, $download_link, $text);
        return $text;
    }
    Posted 12 years ago on Tuesday August 14, 2012 | Permalink
  6. Alex- that worked! Thank you. That function you listed is one created by another plugin. The code you gave is a good template for adding other functions into GF. Thanks!

    Posted 12 years ago on Wednesday August 15, 2012 | Permalink
  7. Thank you for the update.

    Posted 12 years ago on Wednesday August 15, 2012 | Permalink

This topic has been resolved and has been closed to new replies.