Forums

populate fields with data

kraadde 2d ago

Max, I have a php action in my form that reads out user profile data like that:

quote:

// Joomla-Session starten$session = JFactory::getSession();

// Benutzerobjekt holen$user = JFactory::getUser();$userID = $user->id;

if ($userID) {    $db = JFactory::getDbo();

    // Benutzerdefinierte Felder abrufen    $query1 = $db->getQuery(true)        ->select('f.name, fv.value')        ->from('#__fields_values AS fv')        ->join('INNER', '#__fields AS f ON f.id = fv.field_id')        ->where('fv.item_id = ' . (int) $userID);

    $db->setQuery($query1);    $fields = $db->loadAssocList();

    // Benutzerprofilfelder abrufen    $query2 = $db->getQuery(true)        ->select('profile_key, profile_value')        ->from('#__user_profiles')        ->where('user_id = ' . (int) $userID);

    $db->setQuery($query2);    $profiles = $db->loadAssocList();

    // Werte in der Session speichern    foreach ($fields as $field) {        $session->set($field['name'], $field['value']);                // echo $field['name'] . ': ' . $field['value'] . '<br>';    }

    foreach ($profiles as $profile) {        $session->set($profile['profile_key'], $profile['profile_value']);               // echo $profile['profile_key'] . ': ' . $profile['profile_value'] . '<br>';    }}

unquote

The code is doing the expected.

now I want to use some of the values to populate my form fields and have not found the way sofar. Can you give me a hint?

thanks

Max_admin 1d ago

Hi kraade

You can either set the values in the code and use the variable name:

$this->set("variable1", 123); // then you can use {var:variable1} in your form settings

or you can return a single variable and use it using {var:php_action_name}:

return 123; // then you can use {var:php_name}

is this what you are looking for ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kraadde 1d ago

Max,

i modified the php code and the debugger indeed shows the values as follows:[address1] => "some street 2".

When i try to have the value inserted as default in the form field it remains empty.I used to enter {var:address1} in the Defailt value behavieur setting.

Is that the correct way?

Max_admin 1d ago

Hi kraadde

Your PHP action is BEFORE (Above) the field ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.