Autopopulate a field from Community Builder

To populate a field with a value from Community Builder, you will require a script in the Default Value area, for example:

 
//<code>
$user   = JFactory::getUser();
$db   = JFactory::getDbo();
$userId  = $user->get('id');
 
// Is the user logged in?
if ($userId) {
  // Grab the value from the database.
    $db->setQuery("SELECT `firstname` FROM `#__comprofiler` WHERE `user_id`='".$userId."'");
    return $db->loadResult();
}
//</code>
 

The above script returns the first name stored in the #__comprofiler table.


4 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Update a field from Community Builder