Populating a dropdown with User List

simong 22 Oct, 2010
Hi Bob and Max

I have a form that is completed by the Admin... and then also posted to the Admin. It is the first step of a "report" type form.

What I am trying to do is have a drop-down menu that will display the ACTIVE users for the site (at any given time, there will be no more than about 20)

If the ACTIVE users are from a Jooomla "User Group", can you explain the 'best practise" to dynamically extract the list and populate the drop-down?

If you have explained this elsewhere ... can you point me to the post - I have looked, but found little

Thanks for all your great work (once again!!!) TIA
Simon
GreyHead 22 Oct, 2010
Hi Simon,

I posted this a few days ago

My oversight - needed to look deeper in the docs:

echo JHTML::_('list.users', 'user_id', true, 0, NULL, 'name', false);
should do it.

But it only gives a list of all the 'enabled' users, and if I understand correctly you want a list of currently logged in users?

This shows up in the Admin User Manager and it looks as though the info comes by joining he session table into the User query
$filter = ' INNER JOIN #__session AS s ON s.userid = a.id';


I think this means that the 'list.users' method won't work and you'll need to build a new query from scratch.

Bob
GreyHead 24 Oct, 2010
Hi Simon,

OK, in that case the code I posted should be OK.

Bob
simong 25 Oct, 2010
hi Bob

Worked a charm!!! Thanks greatly. My next question will be huge - exporting this data to append an XML document... though will scour the forum and check the coins in my pocket before I return.

BTW. I have validated a site though upgraded and moved the site to a new directory... should I be having any trouble with the VALIDATION if the site has been moved - ie home/content > home/revised

Thanks. Again, thanks for the string.. could not be happier 🙂

Simon
GreyHead 25 Oct, 2010
Hi Simon,

I'm afraid that I don't know how the validation works - please contact Max through the Contact Us form here. I suspect that you may need an updated code.

You can do XML export with the PHP DOM code http://www.php.net/manual/en/book.dom.php takes a bit of getting your head round but it works OK.

Bob
simong 28 Feb, 2011
Hi Bob
I decided to try working backwards in my multiPage form... and now have the 2nd page displaying and writing to the database.
Though I found that a lot of the problem was the "cf_user_id" in the Multi-page PlugIn - using this did not allow me to write to the db correctly - as far as I could see.

So my question... is there a way to get my URL appended with just the "&cf_id=2" (2,3,4 etc)

This is what I was using...

<select="id">
<?php
echo JHTML::_('list.users', 'id', true, 0, NULL, 'name', false);
?></select>


Is there not an easy way to have 'list.databasename', cf_id, etc???

Would much appreciate your help this form is driving me broke! 😟

TIA. Simon
GreyHead 28 Feb, 2011
Hi Simon,

By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look. Please also remind me of the form names (or at leas the mother form).

Bob
GreyHead 01 Mar, 2011
Hi Simon,

I hadn't read your post well enough to work out that you were using the Profile Plug-in inside a multi-page form. It migh be possible to get this to work but probably only by hackign the code somewhere. The plug-in requires a variable passed in the URL but the multi-page plug-in uses a fixed URL.

So, I've turned off the plug-in in the second step and instead I've added code to the Form HTML to look up he values in the database table and display those in the form. That seems to work and is simpler than messing with the plug-in.

Hopefully you can copy my code into the following steps and adapt it to meet the requirements for the step.

Bob
simong 01 Mar, 2011
Hi Bob

I have just come from the site and without looking at the code ... IT WORKS!!! So happy!!!

... later

But Bob, it is not updating the database correctly... it now adds a new entry!!!

😶 😟

Simon
GreyHead 01 Mar, 2011
Hi Simon,

I didn't' look as far as the DB sace - abit pressed to day.

You probably just need to make sure that the primary key of the table (most likely cf_id) is included as a hidden input in the Form HTML.
<input type='hidden' name='cf_id' id='cf_id' value='<?php echo $data->cf_id; ?>' /> 


If you plan to have more that two child forms then I'd enable the DB Connection one each one (after the first in your case).

I'm off for the night here, if you don't find the fix easily leave me a message ans I'll look tomorrow.

Bob
simong 02 Mar, 2011
Hi Bob...
Yep... did the trick. Wish I had some handle on PHP.

One thing I did notice though, and it may have occurred through the process... and that is the "cf_user_id" has been scrubbed back to zero somewhere in the process - I will check it out with a couple of new Member entries.

Thanks for all your assistance... ONCE AGAIN!
Simon
simong 02 Mar, 2011
Bob

Its doing weird stuff... I made back-ups of all 3 forms, and adjust. I create a new Member. Everything is fine, includes a "cf_user_id"

I go into the UPDATE form... everything acts correctly. I changed one of the fields and Submit.

When I go into the database... there is no new entry BUT the "cf_user_id" has been scrubbed and if I try again to re-edit the form, the "data" (the blue copy at the top) is blank, and I am not getting any Member info.

Try the member "Case" - I won't touch it.

I have double, double checked everything... it must be something staring me in the face!!!

Thanks... Simon
GreyHead 02 Mar, 2011
Hi Simon,

I'll take a look a little later but here's my immediate reaction.

the "cf_user_id" has been scrubbed back to zero somewhere in the process


You have to watch this with forms that are intended to be edited by a user. In this case I suspect that you are testing while not logged in and so your user id is 0. ChronoForms is picking this up and correctly over-writing the cf_user_id column (it records the id of the last editor).

You can 'fix' this either (a) by making sure that there is a clue set for cf_user_id before ChronoForms trys to set it - it will then use the pre-set value; or (b) by having a second column to track the user id and let ChronoForms record the id of the last editor.

Which route to use does depend on the work-flow of the application and what you need to track.

Bob
GreyHead 02 Mar, 2011
Hi Simon,

It was as I suspected, adding an extra hidden input fixed the saving problem.

Bob

PS While I was there I re-wrote the code for the drop-down in the first step from so that the drop-down only shows users in the Member's database table. This seems to me to make more sense than listing all users.
simong 02 Mar, 2011
Hi Bob
This form in particular is for an Admin... to enable them to update a client/member's health stats (after each session with them). If possible I would retain the "cf_user_id" for further reference (at a later stage); so will follow your suggestion of (A).

Thanks for the 'select' mod.

In solution "A" therefore, I need (assuming the current, session 'user_id' is indeed "cf_user_id)... something like "cf_user_id ->cf_id". Is this correct and I should be putting this, in the first form around the "hidden value" at the foot of the first page?

(a) by making sure that there is a clue set for cf_user_id before ChronoForms trys to set it



Simon

(I feel I am walking on eggs here... so please excuse my excessive questioning)
simong 03 Mar, 2011
Hi Bob
Changing/keeping the integrity of the "cf_user_id" I found this in another of your threads...

Title: Overwrite previous submission/entry?

Hi,
The following will work (as long as it is executed before the Autogenerated code is):

<?
$db =& JFactory::getDBO();
$user =& JFactory::getUser();

$query = sprintf('SELECT `cf_id` FROM %s WHERE `cf_user_id` = %d',
  $db->nameQuote('#__onlyonce'),
  $user->id
);
$db->setQuery($query);
$result = $db->loadResult();

JRequest::setVar('cf_id', $result ? $result : 0);
?>

Just remember to edit the 'onlyonce' to match your database table..

/Fredrik



Is this usable in my situation?

Simon
GreyHead 03 Mar, 2011
Hi Simon,

I think I already fixed the cf_user_id problem??

Bob
simong 03 Mar, 2011
I don't know Bob!

the "cf_user_id" has been scrubbed back to zero somewhere in the process



and as the form IS for the Admin... he will keep zero-ing the "cf_user_id". These pages are for the Admin. On submitting the second page UPDATE, it is also adding another entry to the database

Simon
GreyHead 03 Mar, 2011
Hi Simon,

The form group Member_Update, mbr_UD1, mbr_UD2 is now working.

There was a DB Connection on both the mother form and the second child form -- that's what gave the additional entry. I've turned off the DB Connection on the mother form.

You also had the DB Connection writing to the jos_users table from the second child form. That's a bad idea 99.9% of the time and even then you need to know exactly what you are doing. You don't need it here as nothing is changing in the jos_users table and I've turned that part off.

Bob
simong 04 Mar, 2011
Bob...
I do not believe it -😮
You are a ... hmmm... much appreciated 🙂

Looks and functions perfectly.
I will come back and present the final code as an example... clean it up, add some comments and hope others can gain some advantage... your input has been invaluable... is much appreciated.

(I will as an aside look at that db table and try to build a cleaner interface for you)

I will return 🙂
Thanks again, Simon
simong 05 Apr, 2011
The full solution to this.. including the editable, resulting page/table can be found shortly in the SHOWCASE thread
This topic is locked and no more replies can be posted.