Forums

DropDown with users list from Joomla!

Ajghell 14 Jun, 2015
Dear All,
I've searched and read many post on this forum (and other so..) but I have not found a clear answer to my question 😢
I would like to create a form to insert an event (data + text box) but linked to users registered in joomla, which have to be extract in a module of Community builder (but this is another story...).
Please help me, with clear indications, to make an dropdown list of Joomla users to insert in my form.
In CF5 there's a demo called "demo-dynamic-data-dropdown" which extract info from groups table. I try to replicate linked this at users table, but doesn't work anymore.

Many thanks
GreyHead 15 Jun, 2015
Hi Ajghell,

You can use a DB Read action to get information from the #__users table, if you set the action up with a Model ID then you can use the Dynamic Data tab of a Select Drop-Down action to add the data to the options.

You haven't said what you want to display in the drop-down, or what values you want to be submitted; and the list of members could get very long!

Bob
lselbach 13 Jan, 2016
Hi Bob,
(renew the question for chronoforms 5 and joomla 3.4.8)

What if the dropdown show the name field in CONTACT LIST (_contact_details joomla table) and as someone is selected, it saves in a variable the email_to field?

I know it is possible but have no clue what the code should be. (This can inside a FAQ too)

Thanks for helping!
Lucas
GreyHead 14 Jan, 2016
Hi Lucas,

Presumably the contact_details table includes the user id so you can set that as the value for the dropdown. Then use that User ID to get the email after the form submits.

Bob
lselbach 14 Jan, 2016
Hi Bob,
Thanks for replying.
Actually the table has user id but I don't know programming, so if you can put a sample code that would be awesome.
(or a link to a detailed faq)

Thanks for helping
Lucas
GreyHead 15 Jan, 2016
Hi Lucas,

Use a DB Read action to get the User ID and the name from the Contact Details table, set these details in the Dynamic Options tab of the drop-down (there's a FAQ about that here).

After the form submits use a second DB Read to look up the selected user-id and get the email.

Bob
lselbach 19 Jan, 2016
Hi Bob,
I'm almost there, but need to know how to pick the value that returned from the array.

Put a CUSTOM CODE after OnSubmit DBRead trying to save as a single variable (didn't worked)
<?php
$cosa = $Data3_array['1'];
?>


And tried to put this variable (cosa) in Dynamic To email action.

So please take a look and watch the debug info, please.

http://brancomiele.com.br/jm/index.php?option=com_chronoforms5&chronoform=contato-db

Thanks a lot, Bob.
Lucas
lselbach 25 Jan, 2016
Please, any help???
GreyHead 26 Jan, 2016
Hi lselbach,

You need the value of the Drop-Down to be the User ID so that you can use that to get information about them after the form submits. Currently you have the name in both the value and the text.

Bob
lselbach 27 Jan, 2016
Please Bob,
I'm almost freaking out here.

I've made what you said and get no results.

I have this in the debuger

        Mailer Error: You must provide at least one recipient email address.

Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => contato-db
    [event] => submit
    [nome] => sdfg sdfg 
    [dropcontatos] => 995
    [textarea6] => sdf gsdfgs dfg 
    [button5] => Submit
    [Data3] => Array
        (
            [id] => 994
            [email] => webaster@e-feo.net
        )

    [ip_address] => 186.233.144.83
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [3] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data3`.`id` AS `Data3.id`, `Data3`.`email` AS `Data3.email` FROM `joom336_users` AS `Data3` LEFT JOIN `joom336_users` AS `data1` ON `Data3`.`id` = `data1`.`id` GROUP BY `Data3`.`id`
                        )

                )

        )

    [2] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below could NOT be sent:
                    [1] => To:
                    [2] => Subject:contato do site
                    [3] => From name:sdfg sdfg 
                    [4] => From email:
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
<table>
<tr><td>Text Label</td><td></td></tr>
<tr><td>Profissional</td><td>995</td></tr>
<tr><td>Cargo</td><td></td></tr>
<tr><td>Descrição</td><td>sdf gsdfgs dfg </td></tr>
</table><br /><br />IP: 16.23.14.83
                )

        )

)



I ONLY want to send the email action to this
[Data3] => Array
(
[id] => 994
[email] => webaster@e-feo.net <----- this email
)

Tried to creat a CUSTOM CODE after 2nd DbRed (on Submit), in a endeavor to store that email from the array inside a variable, but didn't worked.
<?php 
  $cosa = $Data3[0]['email'];
?>


So PLEASE Bob, tell me exactly what to send the message to proper email address.

Thanks a lot
Lucas
GreyHead 27 Jan, 2016
Hi lselbach,

You have 995 as the value of dropcontatos, and then a Data3 array using 994.

Which of these is the user ID you need to use - and where does the Data3 array come from?

Assuming that dropcontatos is the right value the code you need to get the email for that user is
<?php
$juser = JFactory::getUser($form->data['dropcontatos']);
$form->data['user_email'] = $juser->email;
?>
Then you can add use_email in the Email action.

Bob

[[>> later: fixed typo :: <<]]
lselbach 27 Jan, 2016
Hi Bob,
Just realized that all these come and go make a mess.
I can put the email on contact_details table, so I don't need to make relations.
So I did:

1. Created a new form.
2. Created a dbRead onLoad (SETUP)
Enabled YES
Table _contact_details
Multi read YES
Model ID YES / Data1
Fields id,name
order name
3. Created dropdown (DESIGNER)
fieldname dropcontatos
fieldID dropcontatos
Dynamic Data
Enabled YES
Data Path Data1
Value Key id
Text Key name
4. Back to SETUP. Created DBRead OnSubmit
ActionLabel ColocarEmail
Enabled YES
Table contact_details
Multi REad YES
Model ID YES / Data3
Fields id,email_to
5. Right after, created CUSTOM CODE with suggested code
    <?php
    $juser = JFactory:;getUser($form->data['dropcontatos']);
    $form->data['user_email'] = $juser->email;
    ?> 

6. On Email action
Advance / Dynamic To user_email

I can open the list and choose a name.
But when I submit, it doesn't get the value.
The debuging result

        Mailer Error: You must provide at least one recipient email address.

Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => Contato2-db
    [event] => submit
    [nome] => asdfasdf
    [dropcontatos] => 1
    [textarea3] => asdfasdff
    [button4] =>     Enviar    
    [0] => Array
        (
            [Data3] => Array
                (
                    [id] => 1
                    [email_to] => ls@lselbh.com.br
                )

        )

    [1] => Array
        (
            [Data3] => Array
                (
                    [id] => 2
                    [email_to] => 
                )

        )

    [2] => Array
        (
            [Data3] => Array
                (
                    [id] => 3
                    [email_to] => 
                )

        )

    [3] => Array
        (
            [Data3] => Array
                (
                    [id] => 4
                    [email_to] => wester@luclch.com.br
                )

        )

    [ip_address] => 16.23.1.83
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [2] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data3`.`id` AS `Data3.id`, `Data3`.`email_to` AS `Data3.email_to` FROM `joom336_contact_details` AS `Data3` LEFT JOIN `joom336_contact_details` AS `data3` ON `Data3`.`id` = `data3`.`id` GROUP BY `Data3`.`id`
                        )

                )

        )

    [4] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below could NOT be sent:
                    [1] => To:
                    [2] => Subject:Contato Site Bcoiele
                    [3] => From name:nome
                    [4] => From email:
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
<table>
<tr><td>Nome</td><td>asdfasdf</td></tr>
<tr><td>Dropdown Label</td><td>1</td></tr>
<tr><td>Assunto</td><td>asdfasdff</td></tr>
</table><br /><br />IP: 86.23.44.83
                )

        )

)


I'm pretty sure that I must use the contact_details table instead of users table, but I believe that would be simple if I just retrieve the ID field from the ARRAY Data3 and choose the NAME from contact_details

How do I do that?
If it is a code where EXACTLY do I put the code??

Thanks (hope to finish this and stop bothering).
Lucas
GreyHead 28 Jan, 2016
Hi lselbach,

Sorry, there was a typo in my code - please replace :; with ::

But the code won't work if you are getting the email from the #__contact_details table and not the Joomla! User data. Use a DB Read with a Condition set to look for the id that has been submitted.

Bob
lselbach 17 Feb, 2016
Hi Bob,
I'm almost there.
Just put some contacts and tried and everything was fine.

Then I put all 15 contacts and tried again.
And everything is messed up.

Can you take a look pls??



Parse error: syntax error, unexpected ':' in /home/httpd/htdocs/branc2br/jm/administrator/components/com_chronoforms5/chronoforms/actions/custom_code/custom_code.php(20) : eval()'d code on line 2
Data Array

Array
(
    [chronoform] => contato-db
    [event] => submit
    [nome] => Lucas S
    [emailsender] => lslh@gmail.com
    [dropcontatos] => 997
    [textarea6] => Oi Leandro,
Testando o contato do site.
abç
    [g-recaptcha-response] => 03AHJ_Vuvgkc_1Q4z20XVh6rfNDBT_HWue4VRmRCqcsm_sFf8PI8Mq1yeR2wkOGWBXSSx1LuToBEHRAyRH9a9zuVdzUKpSI9e_1DK55U-g4q1gkSVQud5lbgoiYhkj7JJjaThu4Th64F9mA6ictXxI-pDU-kb0h1AsgoOdJWfua7OvDQzUf9rxb5maJOXMEqFl7NnS06CAvT2QsoftGYhQl2MBwGgAchAgb4x2zpFwD_szmLTjS4hFFZDZ6yJOfbY1QW0Y7oRJT_y93gLlLH3sGMPgrZnxtIKeQePufBELbKSJqqA6Z4qWwTmaLl0t5_K7VxMb60PslrTzu_nwdROLo-C2f-feYpGGhjm0ADPfUglOzl7MULuQ6t3rXWrA92iMOS7Fwlfwi7686Xf3-hn7kUwAz5qjK0FHDpFSkmILqwioaxwWxEOy0IDcfDROOGudzDgtZqOPiByujD43xdTPvyf5kpO8PRJaChlGB9NKl_rzp_Bzk7h5O5kW8hPvK0t6-vpIdyHH9oBC_qtNa57xwqvdzz6w0decnMEAbnmNqFWYWAOEBrgziYBxwNAOk9KtAOkAOIOCPWcxjK0GREtETP5DQvi-u5gGv6X2_HwrcRRgauG2PSoNSi2d76ymWkrPdx8nEfdW3t9NdhjVJtMprQCCxHxBYL7CYhrbtX_xg3w_XZdpPKbXl2Mp5k7gYo0TSqAnikFgvv2jQ1y25eTR85L-pJ63kgkncz8eRhs22PY7lEVcuyNZzRvlWTsaQ4eQNQvQ6tLRNzjCi7jfVoYpHtuHcP9B4mUeMplvQFG4UidO86hxYz2fLhr2nP3gz3umXBY6FM3j7URIuF3xLFEgoq7vpiSkGRdr25I986TyWd7KDLk8hi4sq6lb8F30EuGRE-Kdc67KItf5iY603SD-09NU7ZeqcnyaF6cHFBBXGJTRrIMmJpjSUB8
    [button5] => Submit
    [user_email] => ldro@brancomiele.adv.br
    [Data3] => Array
        (
            [user_id] => 995
            [email_to] => lu@luaslbch.com.br
        )

    [ip_address] => 177.101.144.106
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [3] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data3`.`user_id` AS `Data3.user_id`, `Data3`.`email_to` AS `Data3.email_to` FROM `joom336_contact_details` AS `Data3`
                        )

                )

        )

    [2] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:ldro@brancomiele.adv.br
                    [2] => Subject:contato do site
                    [3] => From name:nome
                    [4] => From email:emailsender
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
<table>
<tr><td>Seu Nome</td><td>Lucas Selbach</td></tr>
<tr><td>Seu email</td><td>lsbh@gmail.com</td></tr>
<tr><td>Profissional</td><td>997</td></tr>
<tr><td>Mensagem</td><td>Oi Leandro,<br />
Testando o contato do site.<br />
abç</td></tr>
<tr><td></td><td></td></tr>
<tr><td>Hidden Label</td><td>ldro@brancomiele.adv.br</td></tr>
</table><br /><br />IP: 177.101.144.106
                )

        )

)
lselbach 17 Feb, 2016
BTW,

Form available here
http://brancomiele.com.br/jm/contato.html

1st custom code
<?php
    $juser = JFactory::getUser($form->data['dropcontatos']);
    $form->data['user_email'] = $juser->email;
?>


2nd custom code
<?php
    $juser = JFactory:;getUser($form->data['dropcontatos']);
    $form->data['user_nome'] = $juser->name;
?>
GreyHead 17 Feb, 2016
Hi lselbach,

You still have the ; in the second custom code - and you don't need two
<?php
$juser = JFactory::getUser($form->data['dropcontatos']);
$form->data['user_email'] = $juser->email;
$form->data['name'] = $juser->name;
?>

Bob
This topic is locked and no more replies can be posted.