Dynamic population of the article name

hello all,

I have this code snippet:

add_filter( ‘gform_field_value_article’, ‘article’ );
function article( $value ) {
return ‘dog’

But here I don’t want “Dog” as output, but the respective article name. In the contact form the product should be entered automatically as subject (which is also the article name).

I have been trying to do this for a long time, but I just can’t get it to work.

ChatGPT gave me this:

add_filter( ‘gform_field_value_article’, ‘article’ );
function article( $value ) {
// get the title of the current post
$post_title = get_the_title();

// set the value of the “article” parameter to the title of the current post
return urlencode( $post_title );

However, this only dynamically transfers “contact” to the form, which is not true. It should be the product/post name. The URL of the button from which this whole action is started is like this: https://www.domain73272.xyz/de/kontakt/

Does anyone know what to do?

Do you want the page title (article name) of the page where the form is embedded, or will the visitor be on the article page and click a button to go to the contact page, and you want to populate a field in the form with the title of the article they just arrived from?

Hello Chris,

The case is like this…:
The user is at an article and clicks on “Request a quote”. At the same time he is then redirected to the contact form where he can then provide further information about the order. (Address, email, etc.) In this contact form should then automatically after clicking on “Request offer” the requested product (Which is also the post name). This works so far with this specification:

<a href="/de/kontakt?artikel=Allzweckgetriebe 242.1" class="btn btn-primary btn-lg active" role="button" aria-pressed="true">ANGEBOT ANFORDERN ➜</a>

However, this snippet should only be a PHP query. Because otherwise this must be entered manually in each of over 1000 products (+different languages).
Here under this link you can see what I mean.
At the first product (all-purpose gear 242.1) both buttons are currently active. The one I used in HTML and the hard coded one (which doesn’t pass any data to the form)

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