Forums

Dynamic Email based on two dropdowns

Zanzo76 30 Mar, 2011
Hi to everybody,
I've used a bit Chronoforms to do some simple forms, with some dropdowns, some checkbox, nothing difficult to understand how to do it.
Last week it was told me to do a new thing. I really don't know how to do it, because it envolves some scripts, and I'm not very comfortable with scripting, rather than graphics.

I've a form with two dropdowns, one showing some regions of a country and another with some categories of products.

What I need to achieve is to send the filled-in data to different emails, depending on the choices in the dropdowns by the users.
Also the website will be multilanguage, 5 different languages.

So for example in one region called X, i have two suppliers, one for the product A and another for product B.
So if the user select product A the data will be send to [email]supplier_1@email.com[/email], if the user select product B the data will be send to [email]supplier_2@email.com[/email]. In either cases, and in ALL the cases possible the data will be also send as a CCN field (supplier doesn't need to know about this) to [email]boss@anotheremail.com[/email]

How I could approach this request?

I hope it isn't too much difficult!

Thanks!!
GreyHead 30 Mar, 2011
Hi Zanzo76,

The code for this is in FAQ 31. It's a little bit out of date but should work OK. You'll find several other threads here discussing this.

Bob
Zanzo76 05 Apr, 2011
Hi Bob, thanks for your reply, i've checked FAQ 31, and after some improvement, I've arrangend this html code for the first dropdown:
<select class="cf_inputbox validate-selection" id="select_14" size="1" title="Choose a region from the list"  name="select_14">
    <option value="">Choose from the list</option>
      <option value="region1">region1</option>
      <option value="region2">region2<option>
      <option value="region3">region3</option>
</select>


and this to the second dropdown:


<select class="cf_inputbox validate-selection" id="select_14" size="1" title="Choose a product from the list"  name="select_15">
    <option value="">Choose from the list</option>
      <option value="prod1">prod1</option>
      <option value="prod2">prod2</option>
      <option value="prod3">prod3</option>
</select>


next in the On Submit code - before sending email, I've added the following code:

<?php

$email1 ='test1@email.com';
$email2 ='test2@email.com';
$email3 ='test3@email.com';

$emails = array(
'region1 - prod1'=>$email1,
'region1 - prod2'=>$email1,
'region1 - prod3'=>$email2,

'region2 - prod1'=>$email2,
'region2 - prod2'=>$email3,
'region2 - prod3'=>$email1,

'region3 - prod1'=>$email3,
'region3 - prod2'=>$email1,
'region3 - prod3'=>$email2,
);

$address = $_POST['select_14'].' - '.$_POST['select_15']

$MyForm =&CFChronoForm::getInstance('contact_name');
$MyFormEmails =&CFEMails::getInstance(MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails[address]);
?> 


Where select_14 and select_15 are the region dropdown and the product dropdown. In setup emails I've also builded a 'Dynamic To' field where as value i've used $address but i think i'm doing something wrong with the syntax...

Could you give me an advice?

Thanks 😀
GreyHead 06 Apr, 2011
Hi Zanzo76,

That looks OK except that this line is missing the $ from $address
$MyFormEmails->setEmailData(1, 'to', $emails[$address]);


Bob
Zanzo76 06 Apr, 2011
Hi Bob,
I've solved in this simply way:

<?php
$email1='test1@email.com';
$email2='test2@email.com';

$emails = array(
'Region1 - Prod1'=>$email1,
'Region1 - Prod2'=>$email2,
'Region1 - Prod3'=>$email1,
'Region1 - Prod4'=>$email2,
'Region1 - Prod5'=>$email1,
'Region1 - Prod6'=>$email2,
);

$address = $_POST['select_14'].' - '.$_POST['select_15'];

$submit = $emails[$address];

$MyForm =& CFChronoForm::getInstance('contatti_test');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $submit);
?>


with a static To field in the email setup tab with in it the variable submit without $.

Thanks again for your kind support 8)

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