Is there a way to dynamically populate a "Single Line Text" field with the name of the post it is inserted into?
Is there a way to dynamically populate a "Single Line Text" field with the name of the post it is inserted into?
There is no easy way to do it. You would have to grab the title using WordPress' built-in functions and using out gform_pre_render push it to the field you want.
http://www.gravityhelp.com/documentation/page/Gform_pre_render
http://codex.wordpress.org/Template_Tags/get_the_title
All my best!
Thanks for the head start. Works like a charm and not too much code. Here is a reference for people later. Post in your functions.php file
add_filter("gform_pre_render", "populate_post_name");
function populate_post_name($form){
global $post;
if($form["id"] != 2) // Change [2] to the ID of the form you want to use
return $form;
$post_name = get_the_title($post->ID);
$form["fields"][3]["defaultValue"] = $post_name ; //Change [3] to the nth (-1) field you want to populate.
return $form;
}
Thanks for sharing your code @leepettijohn.