This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Send form results to specific email address based on selected radio button
Started 14 years ago by chuckgreen | 5 posts |
-
Hello,
I need to be able to send form results to multiple and specific email addresses based on a selected radio button on my form. Example: If Radio Button A is selected, the results will go to a different email address than if Radio Button B is selected.
I would appreciate the help. FYI: Very nice app!
Chuck
Posted 14 years ago # -
Hi Chuck,
You can refer to this post :
http://www.appnitro.com/forums/topic/email-from-a-drop-downlist?replies=9#post-2601
It will send "specific" mail based on "drop down" selection, but i can be use for "option/radio" input also. Just make sure to change the form ID and element ID with yours.
MachForm Support
Posted 14 years ago # -
Hi,
First, thanks redityo, the custom_hooks.php mod worked great. But another question: What would the code look like if I had two different "drop downs" on the same form that were to send emails to specific email addresses based on selections? For instance...form1 has a dropdown (element_3) and a dropdown (element_8); I need both to send to different emails based on the different option values of the dropdowns. I am crossing my fingers that this is easy for you. Let me know. Thanks.
Chuck
Posted 14 years ago # -
Hi,
It seems you need to change some code, in my previous code, you can see these code :
function form18_hook_email($params){ //change the email addresses below $email_list[1] = 'sales@example.com'; $email_list[2] = 'hrd@example.com'; $email_list[3] = 'support@example.com'; $email_list[4] = 'accounts@example.com'; $email_list[5] = 'legal@example.org'; $res = do_query("select element_3 from ap_form_{$params['form_id']} where id='{$params['entry_id']}'"); $row = do_fetch_result($res); $attn = $row['element_3']; $target_email = $email_list[$attn]; if(!empty($target_email)){ return $target_email; }else { return true; } }
replace it with
function form18_hook_email($params){ //change the email addresses below //email address list for drop down 1 $email_list1[1] = 'sales@example.com'; $email_list1[2] = 'hrd@example.com'; $email_list1[3] = 'support@example.com'; $email_list1[4] = 'accounts@example.com'; $email_list1[5] = 'legal@example.org'; //email address list for drop down 2 $email_list2[1] = 'one@example.com'; $email_list2[2] = 'two@example.com'; $email_list2[3] = 'three@example.com'; $email_list2[4] = 'four@example.com'; $email_list2[5] = 'five@example.org'; $res = do_query("select element_3,element_8 from ap_form_{$params['form_id']} where id='{$params['entry_id']}'"); $row = do_fetch_result($res); //get email for drop down 1 $attn = $row['element_3']; $target_email = $email_list1[$attn] ; //get email for drop down 2 $attn = $row['element_8']; $target_email .= "," . $email_list2[$attn]; if(!empty($target_email)){ return $target_email; }else { return true; } }
After that, go to this code in "helper-functions.php"
if($target_is_admin){ if(function_exists("form{$form_id}_hook_email")){ $carbon_param['form_id'] = $form_id; $carbon_param['entry_id'] = $entry_id; $carbon_email = call_user_func("form{$form_id}_hook_email",$carbon_param); if(!empty($carbon_email)){ $mail->AddAddress($carbon_email); $mail->Send(); } } }
then change it to
if($target_is_admin){ if(function_exists("form{$form_id}_hook_email")){ $carbon_param['form_id'] = $form_id; $carbon_param['entry_id'] = $entry_id; $carbon_email = call_user_func("form{$form_id}_hook_email",$carbon_param); if(!empty($carbon_email)){ $email_address = explode(',',$carbon_email); foreach ($email_address as $email){ $email = trim($email); if(!empty($email)){ $mail->AddAddress($email); $has_email = true; } } $mail->Send(); $mail->ClearAddresses(); } } }
those code will send notification based on drop down (element_3) and drop_down (element_8) email list
MachForm Support
Posted 14 years ago # -
Hi redityo,
Thank you for the quick response and great code. It works perfectly. There are two more parts to this particular form that have come up and are what I would consider, minor details. What I mean is that I could live without these fixes if necessary. The form is already so feature rich it is sick. The code above you provided HAS solutioned all the particular email addresses that I need to receive the form data. The two emails that you set in the Admin area are not necessary to me. In fact, let me ask the following two questions:
1) In the Admin Control Panel/Manage Forms/Form Name/Emails/Your Users....Is it possible to have the "From Email address" be set to one of the element_id list option emails shown above in the custom_hooks.php file that will be chosen by a user during form submission? Is there a template variable that I can insert there based on your code above?
2) In the Admin Control Panel/Manage Forms/Form Name/Emails/Send notification emails to You.......does it disrupt the script to not fill in the "Your Email Address" so that it is blank and set that "Notifications will be sent to: nobody". For this particular form, there are no other email notifications necessary.
I appreciate your help.
Chuck
Posted 14 years ago #
Reply
You must log in to post.