Chronoform and PHP into HiddenFields

Execute PHP code in ChronoForms hidden fields.

Overview

In CF v6.1.4, placing PHP code directly into a hidden field's value saves the code as text instead of executing it.
Create PHP events in the form's On Load section to return the required server variables, then reference those event variables in the hidden field values.

Answered
ChronoForms v6
in indiana71 03 Jun, 2020
Hi, I have a problem on migrating a form from v 6.0.19. to v 6.1.4 (Designer mode: classic)


Into hidden field I put the following php script

Name: cf_http_user_agent
Value: <?php echo $_SERVER['HTTP_USER_AGENT']; ?>
Save to database ON


Name: refsite
Value: <?php if (!empty($_GET['refsite'])) echo $_GET['refsite']; else echo $_SERVER[HTTP_HOST]; ?>
Save to database ON


well... the old version works perfectly. The new one save the script itself.

Help me, please.
in indiana71 03 Jun, 2020
I need to store into DB the refsite parameter that I pass with GET method to the form and useragent
in indiana71 03 Jun, 2020
Answer
1 Likes
Solved myself.

I created 2 new events into onload section with PHP module
one named:
http_host
return $_SERVER[HTTP_HOST];

the other
http_user_agent
return $_SERVER['HTTP_USER_AGENT'];

then into two hidden field, I insert the following values

refsite
{data:refsite/(var:http_host)}

http_user_agent
{var:http_user_agent}


The question is... is there a way to retrieve $_SERVER[HTTP_HOST], directly from design fields, without create a variable on setup tab before?
Max_admin Max_admin 03 Jun, 2020
Hi indiana,

No, you did it the right way!

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.