Forums

Same contact form with different email recipients

jpmartin815 12 Aug, 2014
Hello,

I have a joomla portal with about 2 thousands K2 articles/items, grouped in various K2 categories.

I am using the latest joomla (version 3.3.3) and the latest K2 (version 2.6.8).

I want to use the latest ChronoForms (version V5 RC6), to create my contact forms, but I have 2 questions, one regarding the plugin level and one the module level:

1). Plugin Level: In every K2 item, I need to set up a contact form with multiple TO, CC and BCC recipients. All K2 items must have the same contact form but each one with different multiple To, Cc and BCc email recipients.

Is it possible to create just one form for all my K2 articles with ChronoForms 5 and just set up for every K2 article different email recipients?

2). Module Level: I need to have a contact form, with a field showing all available categories (i.e. select list field type) but every category must have the option to be linked with many different "To", "Cc" and "BCc" recipients.

In such a case, depending the category that a user is selecting, the message sent could reach only the appropriate recipients. For example, assuming that my joomla website has several categories like "food", "fashion", "sports" etc... and a visitor is searching for something specific in the food category. Is it possible for his message to be sent (via your ChronoForm 5 contact form) only to recipients related to food and not to any other category like fashion or sports?

Thank you very much for your help
Best Regards,
Jean Pierre Martin
GreyHead 13 Aug, 2014
Hi Jean Pierre,

The short answer to both questions is 'Yes' that is possible.

The Email action supports 'dynamic' values for the To BCC and CC values. These will accept the name of a variable is the $form->data array which contains a comma separated list (or, I think an array) of email addresses.

You'd use Custom Code actions - which can include PHP and database queries to take the submitted results from your Contact form; look up the appropriate address lists; and add them to the $form->data array.

Here is a very simple example
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT `email`
        FROM `#__some_table_name`
        WHERE `some_column_name` = '{$form->data['some_input_name']}' ;
";
$db->setQuery($query);
$form->data['cc'] = $db->loadAssocList();
?>
Note ! not tested and may need debugging !

Then put cc in the Dynamic CC box of the Email action.

Bob

Later: updated to correct typo
jpmartin815 13 Aug, 2014
Thank you very much Bob,

I have tried your script after changing $db->loadAssoctList() to $db->loadAssocList(). I have managed to sent a message via a form created with CF5, but only to the first recipient (while I had 2 recipients). The debuging looks like this:

Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => foo2
    [cc] => Array
        (
            [0] => Array
                (
                    [email] => xxx1@yahoo.com
                )
            [1] => Array
                (
                    [email] => xxx2@yahoo.com
                )
        )
)

Do you have any idea?

Thanks again
BR/Jean Pierre
GreyHead 13 Aug, 2014
Answer
Hi Jean Pierre,

Apologies for the typo :-(

That is giving us an array of arrays instead of a plain simple array. Please try $db->loadColumn() instead - I checked the Joomla! docs here and that should be the right one.

Bob
jpmartin815 16 Aug, 2014
Hi Bob,

It works fine. I have also used implode function: implode(',', $db->loadColumn()) to have all emails just separated with a comma🙂

Thank you very much
BR/Jean Pierre
GreyHead 17 Aug, 2014
Hi Jean Pierre,

Excellent, I wasn't sure if the Email action would accept the array without imploding it - I guess not :-(

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