Forums

Email recipient based on user selection

coalescefl 11 May, 2008
Im trying to build a form that emails the form submission to a different person based on a selection list.

For example, the question reads:
I would like more information on:
- Real Estate
- Membership
- Choice 3
- Choice 4

If someone chooses option 1, a copy of the form is emailed to department 1, if option 2, a copy goes to department #2, etc.

Is something like this possible? Any help would be greatly apreciated.

Thanks🙂
Max_admin 11 May, 2008
Possible, in the onsubmit before email :


<?php
if($_POST['real_estate_field']){
$rows[0]->extraemail .= "rea_estate@yourdomain.com";
}
?>


and so...

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mancourt 11 May, 2008
Thank you for your prompt reply! However it's not working =/

I tried the above code and modded it to this to fit the value name:
<?php 
if($_POST['real_estate']){ 
$rows[0]->extraemail .= "email@domain.com"; 
} 
?>



Also the page in question can be found here:
http://goldenocala.coalescecreative.com/index.php/component/chronocontact/?chronoformname=contact_form

Also here is the bit of the form that's pertinate:

<select name="more_info" size="4" multiple id="more_info">
			   <option value="real_estate">Real Estate</option>
			   <option value="membership">Membership</option>
			   <option value="banquet">Banquet/Catering</option>
			   <option value="employment">Employment</option>
		       </select>
Max_admin 13 May, 2008
Hi, sorry my mistake, make this line like this :

$rows[0]->extraemail .= ",rea_estate@yourdomain.com";


cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mancourt 14 May, 2008
Max, thank you again for your reply. Still no dice on the extra E-mails coming in. The primary E-mail is receiving everything fine, just not the ones in here:

<?php
if($_POST['membership']){
$rows[0]->extraemail .= ",email@domain.com";
}
?>

Any other ideas? Thank you
GreyHead 14 May, 2008
Hi mancourt,

I'd add a line of diagnostic code in there:
<?php
if ( $debug ) {
  echo "extraemail: "; print_r($rows[0]->extraemail);echo "<br />";
}
if ( $_POST['membership'] ) {
  $rows[0]->extraemail .= ",email@domain.com";
  if ( $debug ) {
    echo "extraemail: "; print_r($rows[0]->extraemail);echo "<br />";
  }
}
?>
when debug is on this should print out a line showing you what's in 'extraemail' before and after the change.

Bob
mancourt 14 May, 2008
Bob, thanks again for your reply.

Here is what the debug code popped out:

_POST: Array ( [action] => submit [first_name] => NAME [last_name] => LAST NAME [street] => STREET ADDRESS [city] => Port Orange [state] => Florida [zip] => 32127 [phone_daytime] => [phone_evening] => [fax] => [email] => [email]justin@mydomain.com[/email] [contact_preference] => E-mail Address [more_info] => membership [comments] => testing [button] => Submit )
Case 1: Use table layout
extraemail: [email]mainemail@domain.com[/email]
E-mail: 'Yes' custom
Email sent



For some reason the extraemail field is just using whatever the default E-mail I setup, not the one I put in the PHP onsubmit field. It's as if the PHP onsubmit code isn't overriding the default E-mail address for the form.?
GreyHead 14 May, 2008
Hi mancourt,

The PHP check is checking
if ( $_POST['membership'] ) {
but there's no 'membership' field there. I think it should be:
Code:
<?php 
if ( $debug ) { 
  echo "extraemail: "; print_r($rows[0]->extraemail);echo "<br />"; 
} 
if ( $_POST['more_info'] == 'membership' ) { 
  $rows[0]->extraemail .= ",email@domain.com"; 
  if ( $debug ) { 
    echo "extraemail: "; print_r($rows[0]->extraemail);echo "<br />"; 
  } 
} 
?>
Bob
mancourt 15 May, 2008
Bob I think you nailed it! Thank you for the excellent support🙂
mancourt 25 Jun, 2008
Bob, wanted to follow up. Is it possible to get the code above to work with a checkbox scenario so it's easier for users to make multiple selections?
GreyHead 25 Jun, 2008
Hi mancourt,

Yes. Collect the checkbox replies in an array and then run through the array and add an email address for each entry in there.

Bob
mancourt 26 Jun, 2008
Bob, you've already helped me out enough on this one, but could someone help me on building an "array" to make this possible?
GreyHead 26 Jun, 2008
Hi mancourt,

Use this kind of name for yoru checkboxes:
<input type="checkbox" name="checkbox[]" value="value_1" />
<input type="checkbox" name="checkbox[]" value="value_2" />
. . .
and the results will be in the 'checkbox' array.

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