E-mail to selected user from a specific usergroup

SPABO 23 Oct, 2014
Next to sending an email to a selected user user the dynamic-data-dropdown, I wish to see only the users which are in a specific usergroup

The usergroup is called "Docenten" and I can se this in the table jos2_usergroups , with the id nbr. 10

Any ideas how to get this data pulled in the form?
GreyHead 25 Oct, 2014
Hi SPABO,

There's a Joomla! method JAccess::getUsersByGroup('group_id'); that will return an array of all the user-id's from that group. You'd then need to loop through that list to get names and emails for them. There's an example in this StackOverFlow answer.

Bob
SPABO 25 Oct, 2014
But where and how and what to implement this in a dynamic drop down, where I can select a specific user?
(Note : In the V4 version)
GreyHead 26 Oct, 2014
HI SPABO,

Use a Custom Code action in the form ON Load event to get an array of users in the format:
$form->data['users']
  => [0][id] => '111',
         [name] => 'name_a',
  => [1][id] => '222',
        [name] => 'name_b',
. . .

Then you can use this in the Dynamic Date option of the DropDown.

Bob
SPABO 26 Oct, 2014
In this way you load users I think, but I want to load only users from e specific user group
GreyHead 26 Oct, 2014
Hi SPABO,

I told you in my previous post how to get a list of users from a specific group.

Bob
SPABO 27 Oct, 2014
Sorry Bob, for me not clear at all.😟
SPABO 28 Oct, 2014
Sorry for "bumping", but the idea is to load dynamically users which are in a specific usergroup

Currently (with the db multi record loader) I hava ALL the users loaded.

Anybody?
GreyHead 28 Oct, 2014
Hi SPABO,

What code have you taken from the StackOverFlow answer?

Bob
SPABO 29 Oct, 2014
Bob,
Nothing at all, as I simply don't know where to put this.
I also wonder if this generates dynamically the users from a selected/specific usergroup.
Kees
GreyHead 30 Oct, 2014
Hi Kees,

Yes, you asked for code that got the users from a specific group - so that is what it does. I suggest that you try implementing it; you may need to get help with writing the code if that isn't your strength yet.

Bob
SPABO 30 Oct, 2014
Hi Bob,
This is what I "created"
 <?
 jimport( 'joomla.access.access' );
 	$docenten = JAccess::getUsersByGroup(2);
 	jimport( 'joomla.user.user' );
 	foreach($docenten as $docenten){
	$users =& JFactory::getUser($docenten);

	//check if user is NOT blocked or NOT activated yet
	if($users->block == '0' && empty($users->activation)){

     //create array not object for better sorting possibilities
     $docent[$Docenten] = (array) $users;
       }

    }

    array_multisort($docent, SORT_ASC);
    var_dump($docent);
	?>


Not sur if this is okay in this way, but I have no clue how and where to implement it......
Max_admin 02 Nov, 2014
Hi,

Loading users from specific user group(s) will need a Join, a quick way to do this using the GCore framework in v5 is below:

<?php
$list = \GCore\Admin\Models\User::getInstance()->find('list', array('fields' => array('id', 'name'), 'conditions' => array('GroupUser.group_id' => 9)));	

Where 9 is the group id, you can replace it by an array of ids!
The $list variable should have an associative array with keys = users ids and values = users names, you can use 2 different fields if you like.

But then, what would you like to do with this list of users ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 02 Nov, 2014
Perhaps I was not clear on this:

I wish to achieve to select an user , but not just a user , but only an user which is from a specific user-group

The code yoy provided, can I implement this is the current form( which is using the DB read function in "On Load" and "On Submit"???

No clue what you are saying here... :?
need a Join, a quick way to do this using the GCore framework in v5 is below:
Max_admin 02 Nov, 2014
Select it how ? from a dropdown ?

Then what will you do with this user selection ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 02 Nov, 2014
Correct Max,
From a dropdown and sending an e-mail.

Pls find the topic I started on this, but this shows ALL the users
https://www.chronoengine.com/forums/posts/f2/t97735.html?page=3
GreyHead 02 Nov, 2014
HI SPABO,

I have already given you the Joomla! code to do much the same as Max's code. You seem to have got that in the first part of the code you posted but I'm afraid that the last part makes little sense to me :-(

Bob
SPABO 02 Nov, 2014
And still I have nu clue what the both are saying, neither I have a solution.
Max_admin 02 Nov, 2014
Hi SPABO,

if you are using v4 then you will have to do it the way Bob has posted, and you will need a custom code action to format the results (Bob already posted this too) before you feed them to the "Dynamic data" in the dropdown settings.

However, if you are going to use v5 then things will be much easier, first, use this code instead since you will need the list under the model:

<?php
$list = \GCore\Admin\Models\User::getInstance()->find('all', array('fields' => array('id', 'name'), 'conditions' => array('GroupUser.group_id' => 2)));
$form->data["User"] = \GCore\Libs\Arr::getVal($list, array("[n]", "User"), array());

Then in your "Dynamic data" for the dropdown, enter "User" in the "Data path" and id for the "value" and "name" for the "text".

Now, when the form submits you need to find the selected user's email and inject it in the form data array, use this code in a custom code action before the email action:

<?php
$form->data["dropdown_name"] =  \GCore\Admin\Models\User::getInstance()->field("email", array("id" => $form->data["dropdown_name"]));


Finally use "dropdown_name" (which is your dropdown's field name) in the "Dynamic to" of the Email action!
Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 02 Nov, 2014
I have just updated my latest post above because 1 line of code was missing!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 03 Nov, 2014
Tx Max,
😀 😀 This is what I was looking for, just one tiny extra question: How to get the username in the e-mailtemplate as well
Max_admin 03 Nov, 2014
The 2nd piece of code can be repeated to load the "username" field as well!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 04 Nov, 2014
Hi Max,
Whatever I tried to manipulate this code:
    <?php
    $form->data["dropdown_name"] =  \GCore\Admin\Models\User::getInstance()->field("email", array("id" => $form->data["dropdown_name"]));


It brings me a mailer error everytime when sening the the form
Max_admin 04 Nov, 2014
Did you replace the "dropdown_name" with the name of your dropdown field ? then you also have to use that name in the "Dynamic to" box!

You can use a Debugger action to check the final data + email settings!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 04 Nov, 2014
Hi Max,
That's not the issue, what I wish is to have the name of the selected user (from this specific group) in the HTML template of the e-mail as well.

Like
Teachers name : {teacher}
Max_admin 04 Nov, 2014
Then:
$form->data["teacher"] =  \GCore\Admin\Models\User::getInstance()->field("name", array("id" => $form->data["dropdown_name"]));
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 04 Nov, 2014
Sorry, but it still does not pull the teachersname in the template of the e-mail

This is the dropdownname of the dropdown : "docent"
This is what is in the template of the email "Teachers name: {teacher}"
This is the the Custom code in On Submit
<?php
$form->data["docent"] =  \GCore\Admin\Models\User::getInstance()->field("email", array("id" => $form->data["docent"]));
$form->data["teacher"] =  \GCore\Admin\Models\User::getInstance()->field("name", array("id" => $form->data["docent"]));
Max_admin 04 Nov, 2014
Does it send the email correctly ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 05 Nov, 2014
Yep, but as soon as I fill in

$form->data["docent"] =

instead of

$form->data["teacher"] =

I'm getteing the mailer error saying : yoy need to fill out a reciepient's e-mailaddress
Max_admin 05 Nov, 2014
Ok, please use a "Debugger" action at the end of the "on submit" event to check the data values ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 05 Nov, 2014
Here it is Max, only the debuh info on the email part where i have put in {teacher}
    [2] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:my_name@my_ISP.nl
                    [2] => Subject:Kopie van vraag aan een Docent
                    [3] => From name:Admin
                    [4] => From email:my_name@my_ISP.nl
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Body:
<table>
<tbody>
<tr>
<td>De docent</td>
<td></td>  <<<<<<<<<Here I have put in {teacher}, so nothing visibel....🙄 
</tr>
<tr>
<td>Kies jouw docent</td>
<td>xxxxxx@xxxxxx.nl</td>
</tr>
<tr>
<td>Stel hier jouw vraag:</td>
<td>Testing</td>
</tr>
<tr>
<td>Mijn voor-en achternaam:</td>
<td>Charles Spabo</td>
</tr>
<tr>
<td>Mijn e-mailadres:</td>
<td>xxxxx@xxxxxxxxxxxxxxxxxxx.nl</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
Max_admin 05 Nov, 2014
So, the email has been loaded but not the name ? where is the data array debug info ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 05 Nov, 2014
Here the debug info Max
Array
(
    [option] => com_chronoforms5
    [chronoform] => Stel_een_vraag_aan_een_docent_okay
    [event] => submit
    [docent] => xxxx@xxxxxxxx.nl
    [vraag] => testing
    [naam2] => Charles Spabo
    [mail] => aaa@aaaaaaaa.nl
    [chrono_security_answer] => 
    [button3] => Verstuur
    [teacher] => 
    [ip_address] => xx.xx.xxx.xxx
)
Max_admin 06 Nov, 2014
Answer
Yes, the last 2 lines of code we added, we need to just reverse their order:

<?php
$form->data["teacher"] =  \GCore\Admin\Models\User::getInstance()->field("name", array("id" => $form->data["docent"]));
$form->data["docent"] =  \GCore\Admin\Models\User::getInstance()->field("email", array("id" => $form->data["docent"]));

Otherwise, the $form->data["docent"] is changed!! 😉
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 06 Nov, 2014
Hi Max,
That's the solution, it works now perfectly in V5!
Many thanks sofar.

Next step I will undertake to get it als working in V4, but to get every clear and separated, in duw time I will make a new topic (is that's okay)

Kind regards,
Kees
This topic is locked and no more replies can be posted.