Dynamically populate fields with current page url and featured image

I would like to use Gravity Forms to allow a customer to send an Ecard via email. I would like the form to grab the current page’s url and featured image and use these to create an image based on the featured image that is linked to the current page so when someone receives an email they can click on the card image and visit our website to view the product page for that card. How can this be accomplished with Gravity Forms?

Yes, you can do this in Gravity Forms. I just mocked up something similar here:


It’s configured as sort of a “tell a friend” form. Fill it out and you will see on the confirmation the featured image, and also a copy of the message you sent to your ‘friend’. If you use another one of your email addresses, you can see what the ‘friend’ email looks like too.

To make it work, add a single line text field to the form. That will hold the ‘featured image’ URL. I made it a hidden field. For that field, on the advanced tab, check the box “allow field to be populated dynamically” and then give it the parameter name featured_image.

Then, add this code to your theme functions.php or a custom functionality plugin if you are using one:

add_filter( 'gform_field_value_featured_image', 'get_featured_image' );
function get_featured_image( $value ) {
	global $post;
	return get_the_post_thumbnail_url( $post->ID );

That code will populate the field with the URL to the post featured image.

Then, in the notification you can use this to embed the image:

<img src="{Featured image URL:5}" alt="Product Image" />

Field 5 held the URL to the image in my form. That img tag will embed the image based on the URL.

The post title is already available in Gravity Forms using the embed_url merge tag (which I added to the notification as well):

<a href="{embed_url}" title="{embed_post:post_title}">{embed_url}</a>

If you have any questions, please let us know.

1 Like