Retrieve author email address in Sobi2

I am using a form in a Sobi2 item. How can I retrieve the item author's email address in the form?

In order to achieve this, you will need to add a Hidden Field to your form and use a script similar to the following one in it's Default Value area:

 
//<code>
// Get the ID from the URL.
$id  = JRequest::getVar('sobi2Id');
 
// Get a database connection.
$db = JFactory::getDbo();
 
// Setup the query.
$db->setQuery("SELECT `owner` FROM #__sobi2_item WHERE `itemid`='".$db->escape($id)."'");
$owner = $db->loadResult();
 
// A user ID has been found in the database.
if ($owner) {
  // Get the owner's user properties.
  $user = JFactory::getUser($owner);
 
  // Return the email address.
  return $user->get('email');
}
//</code>
 

Note that the code tags from above are mandatory for the script to work.

Was this article helpful?

Yes No
Sorry about that

You Should Also Read

How to store the submission in a file and send it through the email HOT

Automatically grab article author email