× Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues

UserID default in XML

1 year 5 months ago #9974 by Gary Hurdman
UserID default in XML was created by Gary Hurdman
Hi I want to store the current Joomla userId in a field (joomlaid) I realise the below is wrong but how would you do this with the component creator or via editing the XML?

<field name="joomlaid"
value="$user->get( 'id' )"/>

Regards - Paul

Please Log in or Create an account to join the conversation.

2 months 3 weeks ago - 2 months 3 weeks ago #10229 by Howard H. Taylor
Replied by Howard H. Taylor on topic UserID default in XML
In your component's XML file (typically yourcomponent.xml), create a custom field type to fetch the Joomla user ID dynamically.

Here's an example of what your field definition might look like:


Create a custom PHP script for your field type. In your component's PHP folder, you can add a file like fields/joomlaid.php: MyCCPay Portal

defined('_JEXEC') or die;


class JFormFieldJoomlaID extends JFormFieldCustom
protected $type = 'JoomlaID';

public function getInput()
// Get the current Joomla user
$user = JFactory::getUser();
$joomlaID = $user->get('id');

// Create an input field with the Joomla user ID
$html = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="' . $joomlaID . '" readonly />';

return $html;

In your component's PHP folder, create a helper file (e.g., yourcomponent/helper.php) and define the getJoomlaUserID method:

class YourComponentHelper
public static function getJoomlaUserID($element, $value, $node)
// Get the current Joomla user
$user = JFactory::getUser();
return $user->get('id');

Replace YourComponent with your actual component name.

Either of these methods will dynamically fetch and display the current Joomla user ID in the specified field. Choose the one that best suits your component's structure and organization.
Last edit: 2 months 3 weeks ago by Howard H. Taylor.

Please Log in or Create an account to join the conversation.

Time to create page: 0.129 seconds
Powered by Kunena Forum

We use cookies so that you can place orders and we can provide a better service. You can control the use of cookies at the individual browser level. If you reject cookies, you may still use our website, but your ability to use some features or areas of our website may be limited.