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

Email from a drop downlist


  1. anthonybest
    Member

    Is it possible to have the user select who the form is emailed to from a drop down list?

    Posted 15 years ago #
  2. yuniar

    Do you have form review enabled or not?

    I have some hack for this, but would depend on your answer to the above question.


    MachForm Founder

    Posted 15 years ago #
  3. anthonybest
    Member

    Yes, on this specific for I do have it enabled. If the only way to make it work is to disable this, I believe I can turn it off.

    Posted 15 years ago #
  4. yuniar

    Ok, let's take an example with this form:
    http://www.appnitro.com/forms/view.php?id=18

    That form is having form_id = 18 and the "Send Email To" dropdown is having id = "element_3" (view the HTML source to see this)

    The dropdown is having some values:

    <option value="1" >Sales</option>
    <option value="2" >Human Resource Dept.</option>
    <option value="3" >Support</option>
    <option value="4" >Accounting</option>
    <option value="5" >Legal</option>

    To be able sending email to the selected user from the dropdown, follow these steps:

    1) Edit hooks/custom_hooks.php, add this 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;
    	}
    }

    Adjust the function name form18_hook_email to use your own form id number. Also adjust the element_3 with your own dropdown id number.

    Of course, don't forget the email list too.

    2) Edit includes/helper-functions.php, search around line 478 for this code:

    $send_status = $mail->Send();
    $mail->ClearAddresses();

    Right under that code, insert this code:

    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();
    			}
    		}
    }

    3) Edit confirm.php and confirm_embed.php. Around line 20, insert this line:

    require('hooks/custom_hooks.php');

    That would allow you to send email to the selected user from dropdown.
    The code above only work for form with "Form Review" enabled.


    MachForm Founder

    Posted 15 years ago #
  5. anthonybest
    Member

    I have entered the above text. The form returns no error, and saves the data in the form. However the mail does not send. My mail server requires authentication. I have another for where mail is working correctly.

    Is there a change that should be made to add in the authentication information?

    Posted 15 years ago #
  6. anthonybest
    Member

    Please ingore above message. I made changes to my SMTP settings and this is now working perfectly..

    Posted 15 years ago #
  7. franki
    Member

    Is it strange that I tried this process and mine sends email even if I don't have preview enabled??
    However, in both cases it will not send email to the address selected from the menu unless I have an email address fill out in the notification setting. When I do have an address in the notification the form sends to that one and to the selected address from the form.
    How can I eliminate the notification email and only get one from the form option that was selected?

    Thanks again.

    Posted 15 years ago #
  8. redityo

    Hi,

    Hmmm really it send with review page disabled? I will check it. However you can try comment the code on line 478. It will not send to "notification" email, only to the email list from selected options.

    //$send_status = $mail->Send(); <-- comment this
    $mail->ClearAddresses();

    MachForm Support

    Posted 15 years ago #
  9. franki
    Member

    Yeah, is it just me?? Sometimes I'm just lucky I guess :)

    Hey thank you for the tip! That was driving me crazy.

    Posted 15 years ago #
  10. susanfw
    Member

    Is there a way to do this without review being enabled?
    Thank you.

    Posted 14 years ago #
  11. redityo

    It should works without review feature enabled. Have you try it and have a problem ?


    MachForm Support

    Posted 14 years ago #
  12. susanfw
    Member

    My apologies. I was sure I had tried that. I may have tried it with check boxes and had a problem. With the drop down it works fine.
    Thanks

    Posted 14 years ago #
  13. zerostar
    Member

    heya :)

    Excellent solution. Have this working on one of my forms. Have a question though - is it possible to have multiple email addresses in the custom hooks area?

    function form18_hook_email($params){
    
    	//change the email addresses below
    	$email_list[1] = 'sales@example.com,orange@box.com';
    	$email_list[2] = 'hrd@example.com,iris@bluesky.com';
    etc...

    tried it and it doesn't seem to respond.

    TIA :)

    Posted 14 years ago #
  14. redityo

    To have a multiple mail addresses, you need to change these code also

    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();
    			}
    		}
    }

    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_carbon 	= explode(',',$carbon_email);
    
    				foreach ($email_address_carbon as $email_carbon){
    					$email = trim($email_carbon);
    					if(!empty($email)){
    						$mail->AddAddress($email);
    					}
    				}				
    
    				$mail->Send();
    			}
    		}
    }

    MachForm Support

    Posted 14 years ago #
  15. zerostar
    Member

    awesome! works like a dream (of course...)

    thanks so much for the exceptional product and support. I repeat my earlier review - THIS IS EPIC FU!

    Posted 14 years ago #
  16. boyconan90
    Member

    anybody have tested all tricks in this thread on version 2.2? not working on mine :(

    Posted 14 years ago #
  17. boyconan90
    Member

    UPDATE:
    It ONLY work if I activated Send notification emails to

    but, why?

    Posted 14 years ago #
  18. yuniar

    Well, I think that's pretty obvious. If you don't activate the notification emails, MachForm won't send any email.

    Am I missing something?


    MachForm Founder

    Posted 14 years ago #
  19. boyconan90
    Member

    Oh I see...

    Thanks yuniar.

    Posted 14 years ago #
  20. aarondub84
    Member

    Is it possible to do the same thing but with checkboxes rather than a dropdown list?

    Posted 14 years ago #

RSS feed for this topic

Reply »