Hi jbdurand. I was able to accomplish this using the gform_post_submission hook. The hook is documented here:
http://www.gravityhelp.com/documentation/page/Gform_post_submission
That hook allows you to modify the post content after the entry is submitted. Since we have the post_id at that point (after the entry is submitted), it's pretty easy to access everything contained in the post object.
Here's the code I used:
<?php
// change the number 2 below to your form ID
add_action('gform_post_submission_2', 'change_post_content', 10, 2);
function change_post_content($entry, $form) {
// get the post created by this form entry
$post = get_post($entry['post_id']);
// get title of the post
$title = $post->post_title;
// get the site url
$url = site_url();
// build the permalink
$permalink = $url . '/?p=' . $entry['post_id'];
// modify the post_content by appending the URL
$post->post_content .= "\n<br style='clear:both;' />Permanent to this post: <a href='$permalink' title='Permanent link to $title'>$title</a>\n";
// update post
wp_update_post($post);
}
?>
That code will be entered into your theme's functions.php. Here's some documentation on where to put this code.
Here's the reference for the post object:
http://codex.wordpress.org/Function_Reference/get_post
Be sure to change the "_2" on the end of the gform_post_submission hook to your form ID, or remove the _2 altogether if you want this code to be run for all Gravity Forms forms on your site. If you need any more help, please let us know.
Posted 13 years ago on Sunday July 24, 2011 |
Permalink