• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: PHP code custom user fields

PHP code custom user fields 6 years 8 months ago #37207

Hi,

In joomla at users i add some custom user fields.
For example: number of children. ( field name=children)

The need to fill in this on registration.

Now i make a form in RSform Pro with a field: number of children:
What code can display this information and fill in automatic in the form?

In SQL is see: jos_fields and jos_field_values

Thanks

Martijn de Vries
The administrator has disabled public write access.

PHP code custom user fields 5 years 4 months ago #38659

  • zorroson
  • zorroson's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
I would love to see a reply to this, as well.

If anyone have a solution for this, please dont be shy :)

Cheers
The administrator has disabled public write access.

PHP code custom user fields 5 years 4 months ago #38661

  • zorroson
  • zorroson's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
I found it - for anybody else who needs to pull Custom Fields from Users, use the following code which should be added to the items or default value field in your forms field:

//<code>
$customFields = FieldsHelper::getFields('com_users.user', JFactory::getUser(), true); 
return $customFields[1]->value;
//</code>

Change the number in $customFields[x] to select to the custom field you wish. You can find the field id under User Custom Fields in Administrator menu -> Users -> Fields.

Find the ID to the right in the list, and subtract 1 from the ID-number (ie. first field in $customFields array, is called 0). So if you want to pull value from Custom Field ID 1, you type $customFields[0] in the above mentioned code.

Cheers
Last Edit: 5 years 4 months ago by zorroson.
The administrator has disabled public write access.

PHP code custom user fields 4 years 1 week ago #40041

  • contact13
  • contact13's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 30
  • Thank you received: 5
Well, this is weird... I have two custom fields. I used the code in the post above to pre-populate a text box with the value of that particular field. I set the value to "0" for the field with ID of 1. Then I set the other field to a value of 1 since the Field ID is 2. Works great..... Until it doesn't....

The weird part is that if I hard refresh the page a few times, it will randomly swap the values!!! (I even have video of it doing it.) Is it because this table doesn't have a primary key? Is there a way to modify the code to prevent it from loading an incorrect value?

Thanks in advance.
The administrator has disabled public write access.

PHP code custom user fields 4 years 1 week ago #40042

  • contact13
  • contact13's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 30
  • Thank you received: 5
Interestingly enough, I notice that even in the administrator area, if I refresh the screen in the "Custom Fields" tab then I'll a different order of the custom fields. Any ideas on how I can get around this?



The administrator has disabled public write access.

PHP code custom user fields 4 years 1 week ago #40043

  • contact13
  • contact13's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 30
  • Thank you received: 5
Well, on the off chance that anyone is ever reading this in the future, I decided to post the snippet that worked for us. There's likely a better way of doing this, but this gets it done without the field randomizing the order of the values... (I'm still not sure why that table doesn't have a primary key, which would solve the issue all togther).

Hope this helps someone out in the future.
//<code>
$loggedIn;
$user =& JFactory::getUser();
if (!$user->guest) {
  $loggedIn = $user->id;
}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query ->select($db->quoteName(array('field_id', 'item_id', 'value')));
$query->from($db->quoteName('#__fields_values'));
$query->where($db->quoteName('item_id') . " = " . $db->quote($loggedIn));
$query->where($db->quoteName("field_id") . " = 1");
$db->setQuery($query);
$results = $db->loadObjectList();
 
return $results[0]->value;
//</code>
The administrator has disabled public write access.
The following user(s) said Thank You: manuel.berger, mutwirik, gregs, iceferret
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!