Autopopulate a field in RS Forms

4 years 5 months ago #315221 by mikebosh
Autopopulate a field in RS Forms was created by mikebosh
Hi
Trying to autopopulate a field in RS Forms using following script
Works fine for most CB fields except email and name fields get following error
1054 Unknown column 'email' in 'field list'
Any help would be appreciated

//<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>

Please Log in to join the conversation.

4 years 5 months ago #315223 by Astrid
Replied by Astrid on topic Autopopulate a field in RS Forms
Email and name should be called from user table:
//<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 `email` FROM `#__users` WHERE `id`='".$userId."'");
    return $db->loadResult();
}
//</code>
//<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 `name` FROM `#__users` WHERE `id`='".$userId."'");
    return $db->loadResult();
}
//</code>
The following user(s) said Thank You: nant, krileon

Please Log in to join the conversation.

4 years 5 months ago #315226 by mikebosh
Replied by mikebosh on topic Autopopulate a field in RS Forms
Astrid

Great thanks

BW
Mike

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.811 seconds

Facebook Twitter LinkedIn