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?
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?
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
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
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)
(Note : In the V4 version)
HI SPABO,
Use a Custom Code action in the form ON Load event to get an array of users in the format:
Then you can use this in the Dynamic Date option of the DropDown.
Bob
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
In this way you load users I think, but I want to load only users from e specific user group
Hi SPABO,
I told you in my previous post how to get a list of users from a specific group.
Bob
I told you in my previous post how to get a list of users from a specific group.
Bob
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?
Currently (with the db multi record loader) I hava ALL the users loaded.
Anybody?
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
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
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
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
Hi Bob,
This is what I "created"
Not sur if this is okay in this way, but I have no clue how and where to implement it......
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......
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:
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
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
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:
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:
Select it how ? from a dropdown ?
Then what will you do with this user selection ?
Then what will you do with this user selection ?
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
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
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
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
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:
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:
Finally use "dropdown_name" (which is your dropdown's field name) in the "Dynamic to" of the Email action!
Regards,
Max
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
I have just updated my latest post above because 1 line of code was missing!
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
😀 😀 This is what I was looking for, just one tiny extra question: How to get the username in the e-mailtemplate as well
The 2nd piece of code can be repeated to load the "username" field as well!
Regards,
Max
Regards,
Max
Hi Max,
Whatever I tried to manipulate this code:
It brings me a mailer error everytime when sening the the form
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
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!
You can use a Debugger action to check the final data + email settings!
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}
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}
Then:
$form->data["teacher"] = \GCore\Admin\Models\User::getInstance()->field("name", array("id" => $form->data["dropdown_name"]));
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
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"]));
Does it send the email correctly ?
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
Ok, please use a "Debugger" action at the end of the "on submit" event to check the data values ?
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>
So, the email has been loaded but not the name ? where is the data array debug info ?
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
)
Yes, the last 2 lines of code we added, we need to just reverse their order:
Otherwise, the $form->data["docent"] is changed!! 😉
<?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!! 😉
This topic is locked and no more replies can be posted.