Forums

Use custom code to populate text field

heartnewmedia 25 Jan, 2018
Hi

I have tried following examples in other faqs to add a string to a text field using custom code in chronoforms6. I have a text field called 'job' in my form and in the settings, I have created a custom code element in the load section above the display section. My code is:

<?php
$uri=@$_SERVER[HTTP_REFERER];
$pos = strrpos($uri, '/');
$id = $pos === false ? $uri : substr($uri, $pos + 1);
$form->data['job'] = $id;
echo $id;
?>

When I open the form, the string is echoed ok, but the value does not appear in the job field. Any idea what I am doing wrong?

Thanks

Jim
GreyHead 25 Jan, 2018
Answer
Hi JIm,

In CFv6 the syntax to set a value is $this->data('job', $id, true); - please see page 34 of the manual.

Bob
heartnewmedia 25 Jan, 2018
Hi GreyHead - works perfect thank you.

Jim
This topic is locked and no more replies can be posted.