Dynamically Populating based on PHP

Hello GF Community,

I am trying to populate a single text field based on a php webpage. Basically I have a database of products that display on a page using php, when you click a product it will then go to that product page. It is only product information and all I am trying to do is grab the product title so that when I add the single form to all product pages, it will grab the product title from that specific page.

The code that it is using to populate this field is:

<?= $product['Title'] ?>

I have created a dynamic parameter called populate_product

I then added a filter to the php which just caused a critical error so I know I am doing something wrong. I honestly have very little coding knowledge so I am basically just winging it here. Would hugely appreciate any help.

<?php add_filter('gform_field_value_populate_product', function($product['Title']) { return '['Title']'; }); ?>

Cheers, Ty.

If you don’t get any help here you can always checkout WordPress StackExchange

I’d imagine a PHP guru would be willing to help you out there.

Thanks Derek, I will have a look there as well. I know my php is way wrong so someone might be able to help me out there.

1 Like

Hi Tyler,

My guess here is that you could use Populate Anything to get the Product Title populated in a Single Line Text field with no code at all!

A quick demo here: https://www.loom.com/share/f6049c8fca6244d58512f1c0b8f2e572?from_recorder=1&focus_title=1

If you are using a custom DB or a custom table, you should also be able to use Populate Anything to get data into the required field with the database object.


You can use the {embed_post:post_title} merge tag as “Default Value” for a single line text field. When the form is embedded in a single post or page, the post title will populate that field. The merge tags available for the post are explained here:

I just set up a field in a form like that (here’s a screenshot):

Here is that form embedded in a page on my site:

You can make the visibility hidden if you don’t want to see that in the form, but I left it visible so you could see it working.

No PHP or additional plugins required.

1 Like

I appreciate the response guys, the problem is that its not a post that I am trying to get the title from. Its a custom PHP page that grabs information using a custom API. The data is populated from an outside source and not a post or product in wordpress. This is the reason I need to try and grab <?= $product['Title'] ?>.

I have replicated what you both have done, the problem is I need to grab a specific piece of text from the page. It is a product title which has the class “product-title”. Is there any way I can auto-populate a field based on a class on a page?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.