Reputation: 228
I have successfully created a basic Chronoforms form with the standard 'To' field sending the form data in an email to one recipient. However, I would like the 'To' field to become a 'Dynamic To' that will send the form to different users based off of the value of one of the dropdown fields I have in the form. I couldn't find any good documentation on how to use the 'Dynamic To' or accomplish this. Anyone have any thoughts?
Upvotes: 1
Views: 5893
Reputation: 3345
How to show a drop down list of email recipients without displaying the email addresses publicly:
1. ChronoForms v3
Your drop down list in your HTML code will look something like this:
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Person to Contact:</label>
<select class="cf_inputbox" id="select_0" size="1" title="" name="Attn">
<option value="">Choose Option</option>
<option value="President">President</option>
<option value="Secretary">Secretary</option>
<option value="Treasurer">Treasurer</option>
etc
Enter this code in the 'On Submit code - before sending email' field:
<?php
$email_list = array(
'President'=>'[email protected]',
'Secretary'=>'[email protected]',
'Treasurer'=>'[email protected]'
);
$MyForm =& CFChronoForm::getInstance('Contact');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $email_list[$_POST['Attn']]);
?>
This assumes your form name is "Contact".
In "Setup Emails", enter "Attn" in the "To" field.
2. ChronoForms v4
Your drop down list in your HTML code will look something like this:
<div class="ccms_form_element cfdiv_select" id="who_to_contact__container_div">
<label for="Who">Who to Contact:</label>
<select size="1" label_over="0" hide_label="0" id="Who" class=" validate['required']" title="Who" type="select" name="Who">
<option value="President">President</option>
<option value="Secretary">Secretary</option>
<option value="Treasurer">Treasurer</option>
etc
Enter some Custom Code In the Submit section with "Mode" set to "Controller":
<?php
$who = JRequest::getString('Who', 'Webmaster', 'post');
$emails = array(
'President' => '[email protected]',
'Secretary' => '[email protected]',
'Treasurer' => '[email protected]'
);
$form->data['Attn'] = $emails[$who];
?>
In Email -> Dynamic, set "Dynamic To" to: Attn
References:
Upvotes: 0
Reputation: 40685
In chronoform you use the dynamic fields simply by writing the name of the form field into the respective E-Mail field.
So if the name of your dropdown is email_choice
you write email_choice
into the "Dynamic To" field of the E-Mail setup box and you're good to go.
Upvotes: 4