I have been searching the web to find a way to load a list of users into a select box in ChronoForms. So far I have constructed this method:
Custom code loaded on load:
<?php
$name = 'user';
$active = 0;
?>
With this code in the options parameter for the select box config:
<?php echo JHTML::_('list.users', $name, $active); ?>=
Although this works OK for all users, I want to be able to limit the list of user so only a certain group of users are displayed. Also the above method seems to display "> after the select box. Has anyone achieved this before or have any ideas?
Custom code loaded on load:
<?php
$name = 'user';
$active = 0;
?>
With this code in the options parameter for the select box config:
<?php echo JHTML::_('list.users', $name, $active); ?>=
Although this works OK for all users, I want to be able to limit the list of user so only a certain group of users are displayed. Also the above method seems to display "> after the select box. Has anyone achieved this before or have any ideas?
Hi jamesjwarren,
I think that you'll have to build the query by hand. I think this is close to the correct query (but there are only two users on my test site!)
If you get the data like this you can link it to the Dynamic Data tab of a Select Drop-down element in your form.
Bob
I think that you'll have to build the query by hand. I think this is close to the correct query (but there are only two users on my test site!)
SELECT `u`.`id` AS `id`, `u`.`username` AS `username`
FROM `eec8v_user_usergroup_map` AS `g`
JOIN `eec8v_users` AS `u`
ON `g`.`user_id` = `u`.`id`
WHERE `g`.`group_id` = '8' ;
If you get the data like this you can link it to the Dynamic Data tab of a Select Drop-down element in your form.
Bob
Thank you very much for your help, I have got it working using your suggested query.
Just for reference; I have used this code in a custom code event before 'Show HTML':
With dynamic data parameters in my select box:
Data Path = members
Text/Value Keys = name
Just for reference; I have used this code in a custom code event before 'Show HTML':
<?php
$db =& JFactory::getDBO();
$sql="
SELECT `u`.`id` AS `id`, `u`.`name` AS `name`
FROM `#__user_usergroup_map` AS `g`
JOIN `#__users` AS `u`
ON `g`.`user_id` = `u`.`id`
WHERE `g`.`group_id` = '2' ";
$db->setQuery($sql);
$members = $db->loadRowList();
foreach ( $members as $i => $result ) {
$form->data['members'][$i] = array('name' => $result[1]);
}
?>
With dynamic data parameters in my select box:
Data Path = members
Text/Value Keys = name
This topic is locked and no more replies can be posted.