Forums

Using a mult select dropdown and not getting email

danshand84 09 May, 2014
Hi,

I am saving my form data to a db table and sending email. I had everything working to save and send to 1 static email address.

Then I added a mult select dropdown with a different email address coded in the value for each option. I added the Handle Arrays action to before my DB save (the email action is after the db save) and this got the list of emails to be saved correctly to my db field for the mult select drop down. However, now I am not receiving any email (when the email action is set to send email from the drop down select field name). I've tried including the [] and not including the [] in the name on the email set up for the email action. When I use the regular email action, either way I get an error message saying one valid To email address is required, so neither way works. When I use the Email[HG] action I don't get any error message (I get my Show Thanks Message) but no email (when trying with {q5[]} or {q5} (the html name in the select element is q5[]). My goal is to get it to send an email to all the email addresses selected (in the values of the options) - I am under the impression Chronoforms would do that based on the description in the Handle Arrays action in the Basics 2 pdf on the greyhead site (it says: The Handle Arrays action converts array results into a comma separated string that will email or save ‘normally’.). Can you tell what I'm doing wrong?

Thanks for your help,
Dan
Max_admin 09 May, 2014
Hi Dan,

A multi select submits an array of values, please check this page:
https://www.chronoengine.com/faqs/52-cfv4/cfv4-emails/2603-how-can-i-send-an-email-to-different-addresses.html

The code you need to use should be BEFORE the "Handle arrays", you will need to match the values submitted to the addresses list you have!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
danshand84 10 May, 2014
Hi Max,

Thanks for your reply. Actually I did finally get the emails, but using a different approach. I followed this faq: http://www.chronoengine.com/faqs/57-cfv4/cfv4-actions/2643-how-to-send-an-email-dynamically.html, but I used a little different code:
<?php
if ( isset( $_POST["q5"] ) ) {

foreach ( $_POST["q5"] as $val1 ) {

//$favoriteWidgets .= $widget . ", ";
if($val1 == "NJ")
$form->set("email_7", "enabled", 1);
if($val1 == "NY")
$form->set("email_13", "enabled", 1);
if($val1 == "FL")
$form->set("email_15", "enabled", 1);
if($val1 == "NH")
$form->set("email_16", "enabled", 1);

}

}
?>
Also I changed my option values to US state names (NJ, NY, etc) (q5 is the name of the select), and enable different email actions (with static email addresses) depending on my match to the state names; that way the states are saved in the db and displayed on the email which I prefer. This is working , but a couple weird things I don't understand:

1. I actually placed this code AFTER the Handle Arrays and it still works. Is that because I am using the $_POST array instead of the $form->data[] and Handle Arrays does the conversion to the string somewhere other than $_POST (such as $form->data[])?

2. Also after I got this working, the save to the DB failed! I could figure out what was wrong, so I copied the same form and actions to another form (and created an identical table) and both functions are working there! I don't know what is different??

Thanks again,
Dan
GreyHead 10 May, 2014
Hi Dan,

Just to be clear the FAQ is aimed at including the string of results into the body of an email, not at creating an address list.

I think that I am right in saying that the standard Email action won't accept a address list in the Dynamic Email To box (though I'm not certain that I've tested). If it does then the string should be comma separated only - with no spaces and the entry in the box would be just the input name e.g. g5 with no quotes of brackets.

The Email [GH] action should handle an array, or a comma separated string (with or without spaces). Because the To Email box can take a mixture of entries you'd need to use curly brackets to identify a form variable e.g. {q5}.

The easiest way to see what is actually happening is to use a Debugger action.

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