0

This is the part of the code

<td>
        <span class="info_label">
        <?php echo JText::_( "JFORMS_FIELD_CREATED_BY_USERNAME" ); ?>
        </span>:<br />
        <?php echo $this->item->created_by; ?>
    </td>

It obviously return user ID who submitted the form . How can I get username instead? Thanks

1
  • You could get this data from your model. You get "created_by" in your model, so just have a look where the username is saved and include it to your sql-query.
    – MyFault
    Aug 3 '15 at 11:05
2

I'm not sure if this is for a custom component or a core Joomla component, but to get the author's name, you can simply use the following:

<?php echo $this->item->author; ?>

If the component has the option to select an alias for the author, then you should use this instead:

<?php 
    $author = ($this->item->created_by_alias) ? $this->item->created_by_alias : $this->item->author; 
    echo $author;
?>

Update:

<?php
    echo JFactory::getUser($this->item->created_by)->get('username');
?>
5
  • this is a jForms component by Giro. Sorry forgot to mention Aug 3 '15 at 11:14
  • and in the model I have : //Defines automatically the author of this element $table->created_by = JFactory::getUser()->get('id'); Aug 3 '15 at 11:28
  • @OlegAgadjanyan - Please see my updated answer. You don't need to store the username in the database. You can get the username based on the ID you have stored and display it as shown.
    – Lodder
    Aug 3 '15 at 11:32
  • It worked like a charm. Thank you !!! Another question . how can retrieve the rest of information. e.g. from User Profile (city/country/region) Aug 3 '15 at 12:29
  • JUserHelper::getProfile($userId); Look at this answer for a complete example: joomla.stackexchange.com/a/902/154
    – fruppel
    Aug 3 '15 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.