• 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: Autopopulate Users into Dropdown List from Table

Autopopulate Users into Dropdown List from Table 14 years 2 months ago #12658

Hi there,

I found this documentation,

http://www.rsjoomla.com/customer-support/documentations/34-custom-scripting/94-auto-populate-a-list-from-a-table.html

but I am unsure of how to use it correctly to pull user data from either the core Joomla database, or Community Builder.

Any help as to what goes in:
your_value, your_label, your_table

would be GREATLY APPRECIATED!!

Thanks!
The administrator has disabled public write access.

Re:Autopopulate Users into Dropdown List from Table 14 years 2 months ago #12672

Submitted a ticket and received a speedy response - thanks!

For everyones benefit - here it is:



Andrei Cristea:
Hello,

You will have to choose the table you want to retrieve information from, for example if you with to extract the information from the default Joomla! user table you will need to use "#__users" instead of "your_table". Next you will need to select the information you want to use as a label and value for your dropdown from the columns available in that table. For example:

//<code>
$items = "|Please Select[c]\n";
$db =& JFactory::getDBO();
$db->setQuery("SELECT name, username FROM #__users");
$result = $db->loadObjectList();

foreach ($result as $r)
$items .= $r->username . '|' . $r->name . "\n";

return $items;
// </code>

This will autopopulate a dropdown list with the names as values and usernames as labels of all the users in the #__users table.

Regards!



NOTE - I wanted to use the users NAME, rather than USERNAME, so I switched everything that has username to name.

Worked perfectly. Thank again!
The administrator has disabled public write access.

Re:Autopopulate Users into Dropdown List from Table 14 years 1 month ago #13106

  • ipokkel
  • ipokkel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 1
If using the example above it creates a line break after the last item resulting in a dropdown with whatever gets loaded from the db plus a blank line at the bottom, e.g.:
-> Please Select
-> John|John Player
-> Peter|Peter Pan
->

Simply add a trim statement to clear the unnecessary line break after the last value.
//<code>
$items = "|Please Select[c]\n";
$db =& JFactory::getDBO();
$db->setQuery("SELECT name, username FROM #__users";
$result = $db->loadObjectList();
 
foreach ($result as $r)
$items .= $r->username . '|' . $r->name . "\n";
 
return trim($items);
// </code>
The administrator has disabled public write access.
The following user(s) said Thank You: dasaing

Re:Autopopulate Users into Dropdown List from Table 13 years 7 months ago #14651

i am confused. not very good with the codes. I made a drop down "name" then put the code as above in the script section. with script tags... that doesn't work. I submitted a trouble ticket but just got the generic response with basic code. nothing on how to put it into action.

If anyone can really help, I need to actually select another form's submitted info (name, email, mailing address, phone, and several other fields) then fill in these field automatically. I know this is complicated. if someone can do this, please contact me directly.... info at azphotos dot net

Thanks
The administrator has disabled public write access.

Re:Autopopulate Users into Dropdown List from Table 13 years 6 months ago #15157

  • spartan
  • spartan's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Any update on this? I am looking to accomplish the same thing:

I have 2 forms: address book and order form. The address book allows users to create a contact list so they can auto populate the order from with entries from the information (contacts) they submitted on the address book form.

Is there a way to accomplish this?
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 11 years 3 months ago #26051

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
I'm looking for something similar but not quite the same

There are two fields in my form {city} and {officeaddress}

I want a customer to select {city} from a select box

I then want a text area {officeaddress} to autopopulate based on the value selected in {city}

I then need to store {officeaddress} in 'cb_officeaddress' in Community builder

To put it simply, I want to SET 'cb_officeaddress'={officeaddress} WHERE 'cb_city'={city:value} AND 'id'={userid:value}

I had some limited success with this by creating a list in a select box like this -

Allerdale Borough Council<br />Allerdale House<br />Workington<br />Cumbria CA14 3YJ<br />|Allerdale

I can then autopopulate jos_comprofiler 'cb_officeaddress' but when I autopopulate the office address in a text area on a different form I can't get the address lines to wrap and the office address displays like this -

Allerdale Borough Council<br />Allerdale House<br />Workington<br />Cumbria CA14 3YJ<br />|Allerdale

What I seem unable to do is display the office address in a text area like this -

Allerdale Borough Council
Allerdale House
Workington
Cumbria CA14 3YJ

This is also how I want it to appear in a user email that will be sent to the particular council

I've spent the whole of christmas trying to get this to work and I'm pulling my hair out ...any help or ideas would be greatly appreciated.
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 10 years 5 months ago #29564

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
There seems to be a problem with this code when retrieving values from jos_rsform_submission_values

//<code>

//the section

$db->setQuery("SELECT DISTINCT Fieldvalue, FieldName FROM jos_rsform_submission_values" WHERE FieldName="Username" AND FieldValue IS NOT NULL);

//Returns an empty query!

// </code>


It appears that ‘WHERE’ can not be used in conjunction with this code to filter jos_rsform_submission_values!
Last Edit: 10 years 5 months ago by Roberts.
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 10 years 4 months ago #29614

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
It seems there were some syntax errors in your query, please try the following:
//<code>
 
//the section
 
$db->setQuery("SELECT DISTINCT `Fieldvalue`, `FieldName` FROM #__rsform_submission_values WHERE `FieldName`='Username' AND `FieldValue` IS NOT NULL");
 
$db->loadObjectList(); 
 
//Returns an empty query!
 
// </code>
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 4 months ago by cosmin.cristea.
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 9 years 9 months ago #31635

Thank you all for the above. I have very limited experience with coding and I am trying to achieve a slight modification of the above.

Could anyone please help me out with some sample code that would allow me to auto populate a drop down menu with a list of the site's registered users. Ideally I want the display to be the "full name" and the value to be the "email".

E.g. If my registered users were, Harry, Bruce and Clark. The form would display the following in the dropdown menu:

Please select
Harry Potter|Harry@someweb.org
Bruce Wayne|Bruce@batcave.com
Clark Kent|Clark@superman.com

And as more users registered, the menu automatically includes them.

Many thanks in advance!

Ed
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 9 years 9 months ago #31642

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Try this:
//<code>
$db = JFactory::getDBO();
$db->setQuery("SELECT `name`, `email` FROM #__users");
$rez = $db->loadObjectList();
$items = "|Select...\n";
foreach($rez as $r){
	$items .= $r->email."|".$r->name."\n";
}
return trim($items);
//</code>
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
The following user(s) said Thank You: edward.palmer

Autopopulate Users into Dropdown List from Table 9 years 9 months ago #31645

Brilliant, this worked perfectly. Many thanks.
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 9 years 8 months ago #31973

As a modification to this code, could I call for just the users assigned to a particular group (i.e. registered, authors, etc.)

Thanks again!
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 9 years 8 months ago #31999

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

User Groups IDs are found in the #__usergroups database table. Knowing the Group's exact ID, you can try a similar as the following snippet (usually the Registered user group has ID 2):
//<code>
$userGroupId = 2;
$db = JFactory::getDBO();
$db->setQuery("SELECT u.`name`, u.`email` FROM #__users AS u LEFT JOIN #__user_usergroup_map AS um ON u.`id` = um.`user_id` WHERE um.`group_id`='".$userGroupId."'");
$rez = $db->loadObjectList();
$items = "|Select...\n";
foreach($rez as $r){
	$items .= $r->email."|".$r->name."\n";
}
return trim($items);
//</code>
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.

Autopopulate Users into Dropdown List from Table 8 years 4 weeks ago #36698

  • Roberts
  • Roberts's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 54
  • Thank you received: 1
So if you want

user | email

it would be
//<code>
$db = JFactory::getDBO();
$db->setQuery("SELECT `name`, `email` FROM #__users");
$rez = $db->loadObjectList();
$items = "|Select...\n";
foreach($rez as $r){
	$items .= $r->email."|".$r->name." | ".$r->email."\n";
}
return trim($items);
//</code>
The administrator has disabled public write access.
  • 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!