Forums

Dynamic To Fields Help

andybeck 26 Jan, 2010
First of all let me say that I love ChronoForms. It is a must have component for any Joomla powered site.

I am trying to create a simple form that will email the results, but I need the user to select who receives the email. I'm using V3.1 RC5.5

The form is on a site that has two physical locations. I would like for the user to select from either a radio button, or drop down, which location is to receive the contents of the form. I'm trying to avoid creating a seperate form for each location.

I thought I could use two of the Dynamic To fields, but I don't know how to include the email address for each selection. (radio or drop down)

I know this is possible, but I need someone to point me in the right direction.

Thank you in advance for your help.
Andy Beck
andybeck 26 Jan, 2010
Ok...I just found the method outlined in FAQ 31 and gave it a try in a simple form I named test, but I cant get it to work. Below is the code I used.

Form Code:
<div class="form_item">
  <div class="form_item">
Select the recipient you wish to contact:<select name="recipients">  <option value="em1">Jasper</option>  <option value="em2">Calhoun</option></select>
      

    </div>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Subject</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="Subject required" id="text_1" name="text_1" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Message</label>
    <textarea class="cf_inputbox required" rows="3" id="text_2" title="" cols="30" name="text_2"></textarea>
    <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Message :: Message required</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_3" type="submit" /><input type="reset" name="reset" value="Reset"/>
  </div>
  <div class="cfclear"> </div>
</div>


On Submit code - before sending email:
<?php$emails_2 = array('em1'=>'example1@example.com', 'em2'=>'example2@example.com',);$MyForm =& CFChronoForm::getInstance('test');$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);?>


I used a Dynamic To field and gave it the value recipients.

When I submit the form, I get the following error, and it won't send any emails.

Parse error: syntax error, unexpected T_VARIABLE in /home/mysite/public_html/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 1



Any help would be appreciated.
GreyHead 26 Jan, 2010
Hi Andy,

There are several examples here and the basic code you need is in one of the FAQs (#36 from memory) - the technique is used there to avoid showing email addresses in the Form HTML.

Bob
andybeck 26 Jan, 2010
Bob,

Thanks for the reply. If you'll look at my reply to my own post, I found what I was looking for in FAQ 31, but have failed to get it to work.

Ok...I just found the method outlined in FAQ 31 and gave it a try in a simple form I named test, but I cant get it to work. Below is the code I used.

Form Code:
<div class="form_item">
<div class="form_item">
Select the recipient you wish to contact:<select name="recipients"> <option value="em1">Jasper</option> <option value="em2">Calhoun</option></select>


</div>

</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Subject</label>
<input class="cf_inputbox required" maxlength="150" size="30" title="Subject required" id="text_1" name="text_1" type="text" />

</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textarea">
<label class="cf_label" style="width: 150px;">Message</label>
<textarea class="cf_inputbox required" rows="3" id="text_2" title="" cols="30" name="text_2"></textarea>
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Message :: Message required</div>
</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_button">
<input value="Submit" name="button_3" type="submit" /><input type="reset" name="reset" value="Reset"/>
</div>
<div class="cfclear"> </div>
</div>


On Submit code - before sending email:
<?php$emails_2 = array('em1'=>'example1@example.com', 'em2'=>'example2@example.com',);$MyForm =& CFChronoForm::getInstance('test');$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);?>

I used a Dynamic To field and gave it the value recipients.

When I submit the form, I get the following error, and it won't send any emails.

Parse error: syntax error, unexpected T_VARIABLE in /home/mysite/public_html/components/com_chronocontact/libraries/customcode.php(64) : eval()'d code on line 1



Thanks again for your help
GreyHead 26 Jan, 2010
HI Andy,

Just off to bed but it looks as though the first line of the OnSubmit code needs some punctuation - especially a space or line return after <?php

Bob
andybeck 26 Jan, 2010
That was it...just put a line break in there and it worked fine. I get in a hurry sometimes and miss the small stuff.

Thanks for all your help Bob, and thanks for a great component.

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