How to get product name from one of the static pages to the form

How to pass product name from a static page to a CF form.

Overview

The issue occurs when a single form is used across multiple static product pages, requiring the page-specific product name to be automatically populated in the form.
Store the product name in the article's alias or note field, then use a custom PHP code action in CF to retrieve and set this value as the default for the corresponding form field.

Answered
ChronoForms v6
se serguei_kp 24 Dec, 2020
Hello Chronoform, Merry Christmas!
I need your help to get product name from a static page to the form.
Lets consider next scenario:
I've got several product pages A, B, C and I have one form F, this form is published (shared) via module on each product page.
Is it possible, when page C is loaded to get product name of page C into the form and so on,
if page B is loaded get product name B to the form?
​
In other words, I would like to have one form for several static html pages (no database queries), and get the data from the page to the form, when this page is loaded.
​
​
Best regards.
Gr GreyHead 28 Dec, 2020
Hi serguei_kp,
​
ChronoForms adds the variables from the page URL into the form data when the form is loaded. If you temporarily add a debugger action to the Form Load event you can see the data. You can then use this to set the value of a hidden input in the form which will identify the page when the form is submitted.
​
Bob
se serguei_kp 28 Dec, 2020
Answer
Hello Bob, thank you!
​
I found the solution, I put the values (product name and product type) in alias and note field of an article, and then retrieve it with PHP code.
​
Just add : {var:default_service_name_php} or {var:default_service_type_php}
in the field Value of each feild where you need to load default value.
​
PHP code:
Name: default_service_name_php
$article_title = '';
$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);$article_alias = $article->get('alias');
return $article_alias;
​
PHP code:
Name: default_service_type_php
$article_title = '';
$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_note= $article->get('note');
return $article_note;
This topic is locked and no more replies can be posted.