Joomla user data into CFv6 form field

How to populate a CF form field with logged-in Joomla user data.

Overview

The issue occurs when custom PHP code retrieves user information but does not correctly assign it to the form field.
Use the provided shortcode in the form field's value setting or ensure the PHP data method includes the correct parameters to pass the value.

Answered
do doromi 26 Jul, 2018
Hi,

I'm trying to get the data of logged-in people into a form.

I put a custom code into the load part of my form on top of the display section:

<?php
$user =\JFactory::getUser();
$user_id= $user->get('id');

if ($user_id <> "")
{
$vollname= $user->get('name');
$nachname= trim(strrchr($vollname,' '));
$vorname= substr($vollname, 0, strlen($vollname)-strlen($nachname)-1);
$teilnehmer = $nachname .", ".$vorname;

$this->data("teilnehmer", $teilnehmer);
}

I do get the data in the way I need them, but I don't know how to put them into the form field "teilnehmer",
so I assume the last code line is not correct.

Could anybody please tell me how to get the $teilnehmer into the text field "teilnehmer" ?

Thanks in advance,

Doris

he healyhatman 26 Jul, 2018
You can just use the shortcodes. In the text box under "value" put {user:name}
he healyhatman 26 Jul, 2018
Answer
In PHP to set the data use $this->data("field", "value", true);

Or return the value you want and then in value put {var:phpname}
do doromi 26 Jul, 2018
Hi healyhatman,

thanks a lot - I got it working!

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