[FORMINATOR PRO] Email Notification Routing

Hi there,

I would like to request the following feature:

-Routing – Allows notification to be sent to different email addresses depending on values selected in the form

LIKE this https://docs.gravityforms.com/email-routing-gravity-forms-confirmations/

  • F404
    • Flash Drive

    Hello

    1. Then in previous answer why i get this answer :

    Sat Feb 16 2019

    I can see this task having a “high” priority so this should be included in a near-future update.

    2. Current version version is 1.7.0.1

    1.7.5 to 1.7.6. this update will be 2 years later :smiley:

    • Nastia
      • Support Rock Star

      Hello F404

      Hope all is well!

      I am afraid we do not share an exact ETA, to prevent disappointment if a deadline is missed (which in plugin development quite a frequent occurrence!). Two years is a long time, I believe the feature development will not take this long :wink:

      The feature is under development, once it will be completed and will pass all the testing it will be released. Our goal is to release a bug-free plugin :smiley:

      We really appreciate your patience in here!

      Kind regards,

      Nastia

  • Prathamesh Palve
    • Staff

    Hey F404,

    I went ahead and made a few tests after which I found that you can make is possible if you use radio field but I'm afraid it would not be currently possible for a selection field. Here is how you can make it possible to do it with the radio field.

    Step 1: Create a Radio Field. In each radio option, enter the email id you which to have the email if that option is selected as shown below:

    [image pos="0"]

    Also, Create an Email Address section in the same form to accept user email.

    Step2: I have seen that the functions would not work properly if you create things in the Admin Confirmation email. We have already tasked that and we would be worked out soon. For now, we would be using Confirmation Emails Section for this purpose. That is in the Email Notification section, we would use the Confirmation email to send emails to the Admins and the user too as of now. Here is how we will be doing it:

    Here the Radio option will send emails to the specific emails and the email option will send an exact copy of the same to the user too(Highlighted in RED BOX). If you do not want the user to receive an email you can just add the Radio option.

    I'm aware this way we would not be able to send a different custom email to the user filling the form. As I said we have tasked this to be enabled in the Admin Email so both the functionalities can be achieved. This is just a temporary solution which should work for you. We will soon come up with the functionality to enable the same in the Admin Email.

    If you have any doubts or need any help, feel free to reply in the threads here and we would be happy to help you with it.

    Thanks,

    Prathamesh

  • Prathamesh Palve
    • Staff

    Hello F404,

    To make this possible, please navigate to the Forminator-> Forms-> Edit form-> Email Notifications-> Confirmation Email-> Message Body-> Add Form Data. Add the fields individually for example: `{radio-1}

    {email-1}`

    If you use the all fields form data option( {all_fields} ), it would not be possible with it. Can you try this on your end once and let me know if that works for you? I am looking forward to hearing from you.

    Thanks,

    Prathamesh

  • Panos
    • SLS

    Hi F404 !

    You can try adding the following snippet in a mu-plugin :

    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){

    //$field_slugs = array( 'select-1', 'select-2' );

    $ignored_field_types = Forminator_Form_Entry_Model::ignored_fields();
    $form_fields = $custom_form->get_fields();
    if ( is_null( $form_fields ) ) {
    $form_fields = array();
    }
    $html = '<br/><ol>';
    foreach ( $form_fields as $form_field ) {

    //if ( in_array( $form_field->slug, $field_slugs ) ) {
    if ( 'select' == $form_field->raw['type'] ){

    $value = render_entry( $entry, $form_field->slug );

    if ( empty( $value ) ) {
    $value = isset( $_POST[ $form_field->slug ] ) ? $_POST[ $form_field->slug ] : '';

    }

    if( ! empty( $value ) ) {

    $options = $form_field->raw[ 'options' ];

    foreach ( $options as $key => $option ) {
    if ( isset( $option['label'] ) && isset( $option['value'] ) && $value == $option['value'] ) {
    $html .= '<li>';
    $label = $form_field->get_label_for_entry();
    $option_label = $option['label'];

    if ( ! empty( $label ) ) {
    $html .= "<b>{$label} : {$option_label}: <br />";
    }
    $html .= "Value : {$value} <br />";
    $html .= '</li>';

    }
    }

    continue;
    }

    }

    // @var Forminator_Form_Field_Model $form_field
    $field_type = $form_field->__get( 'type' );
    if ( 'section' === $field_type ) {
    $value = $form_field->__get( 'section_title' );
    if( ! empty( $value ) ) {
    $html .= '</ol>';
    $html .= '<h4><b>' . $value . '</b></h4>';
    $html .= '<ol>';
    }
    } elseif ( 'html' === $field_type ) {
    $label = $form_field->get_label_for_entry();
    $value = $form_field->__get( 'variations' );
    $content = forminator_replace_variables( $value, $custom_form->id, $data['current_url'] );
    $html .= '</ol>';
    $html .= '<h4><b>' . $label . '</b></h4>';
    $html .= $content;
    $html .= '<ol>';

    } else {
    if ( in_array( $field_type, $ignored_field_types, true ) ) {
    continue;
    }
    $value = render_entry( $entry, $form_field->slug );
    if( ! empty( $value ) ) {
    $html .= '<li>';
    $label = $form_field->get_label_for_entry();

    if ( ! empty( $label ) ) {
    $html .= '<b>' . $label . '</b><br/>';
    }
    $html .= $value . '<br/>';
    $html .= '</li>';
    }
    }
    }
    $html .= '</ol><br/>';

    return $html;
    }, 20, 5 );

    That should check all select fields in the form. If you need to specify then you need to un-comment lines:

    //$field_slugs = array( 'select-1', 'select-2' );

    and

    //if ( in_array( $form_field->slug, $field_slugs ) ) {

    and comment out line:

    if ( 'select' == $form_field->raw['type'] ){

    You will also need to set the proper fields in the first line that was un-comented.

    Hope this helps!

    Kind regards!

  • Prathamesh Palve
    • Staff

    Hello F404,

    You can try to add the following code by replacing the above code:

    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){
    if( ! in_array( $custom_form->id, array( 1,2,3 ) ) return $html;
    //$field_slugs = array( 'select-1', 'select-2' );

    $ignored_field_types = Forminator_Form_Entry_Model::ignored_fields();
    $form_fields = $custom_form->get_fields();
    if ( is_null( $form_fields ) ) {
    $form_fields = array();
    }
    $html = '
    <ol>';
    foreach ( $form_fields as $form_field ) {

    //if ( in_array( $form_field->slug, $field_slugs ) ) {
    if ( 'select' == $form_field->raw['type'] ){

    $value = render_entry( $entry, $form_field->slug );

    if ( empty( $value ) ) {
    $value = isset( $_POST[ $form_field->slug ] ) ? $_POST[ $form_field->slug ] : '';

    }

    if( ! empty( $value ) ) {

    $options = $form_field->raw[ 'options' ];

    foreach ( $options as $key => $option ) {
    if ( isset( $option['label'] ) && isset( $option['value'] ) && $value == $option['value'] ) {
    $html .= '
    <li>';
    $label = $form_field->get_label_for_entry();
    $option_label = $option['label'];

    if ( ! empty( $label ) ) {
    $html .= "<b>{$label} : {$option_label}: ";
    }
    $html .= "Value : {$value} ";
    $html .= '</li>
    ';

    }
    }

    continue;
    }

    }

    // @var Forminator_Form_Field_Model $form_field
    $field_type = $form_field->__get( 'type' );
    if ( 'section' === $field_type ) {
    $value = $form_field->__get( 'section_title' );
    if( ! empty( $value ) ) {
    $html .= '</ol>
    ';
    $html .= '<h4><b>' . $value . '</b></h4>';
    $html .= '
    <ol>';
    }
    } elseif ( 'html' === $field_type ) {
    $label = $form_field->get_label_for_entry();
    $value = $form_field->__get( 'variations' );
    $content = forminator_replace_variables( $value, $custom_form->id, $data['current_url'] );
    $html .= '</ol>
    ';
    $html .= '<h4><b>' . $label . '</b></h4>';
    $html .= $content;
    $html .= '
    <ol>';

    } else {
    if ( in_array( $field_type, $ignored_field_types, true ) ) {
    continue;
    }
    $value = render_entry( $entry, $form_field->slug );
    if( ! empty( $value ) ) {
    $html .= '
    <li>';
    $label = $form_field->get_label_for_entry();

    if ( ! empty( $label ) ) {
    $html .= '<b>' . $label . '</b>';
    }
    $html .= $value . '';
    $html .= '</li>
    ';
    }
    }
    }
    $html .= '</ol>
    ';

    return $html;
    }, 20, 5 );

    I have just added the following additional code before the code suggested by Panos:

    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){
    if( ! in_array( $custom_form->id, array( 1,2,3 ) ) return $html;

    Hope this helps!

    Regards,

    Prathamesh

  • Prathamesh Palve
    • Staff

    Hello F404,

    I am sorry for that. I see we missed adding a close bracket in a line. Here is the updated and rechecked code:

    add_filter( 'forminator_get_formatted_form_entry', function( $html, $custom_form, $data, $entry, $ignored_field_types ){
    if( ! in_array( $custom_form->id, array( 1,2,3 ) ) ) return $html;
    //$field_slugs = array( 'select-1', 'select-2' );

    $ignored_field_types = Forminator_Form_Entry_Model::ignored_fields();
    $form_fields = $custom_form->get_fields();
    if ( is_null( $form_fields ) ) {
    $form_fields = array();
    }
    $html = '<br/><ol>';
    foreach ( $form_fields as $form_field ) {

    //if ( in_array( $form_field->slug, $field_slugs ) ) {
    if ( 'select' == $form_field->raw['type'] ){

    $value = render_entry( $entry, $form_field->slug );

    if ( empty( $value ) ) {
    $value = isset( $_POST[ $form_field->slug ] ) ? $_POST[ $form_field->slug ] : '';

    }

    if( ! empty( $value ) ) {

    $options = $form_field->raw[ 'options' ];

    foreach ( $options as $key => $option ) {
    if ( isset( $option['label'] ) && isset( $option['value'] ) && $value == $option['value'] ) {
    $html .= '<li>';
    $label = $form_field->get_label_for_entry();
    $option_label = $option['label'];

    if ( ! empty( $label ) ) {
    $html .= "<b>{$label} : {$option_label}: <br />";
    }
    $html .= "Value : {$value} <br />";
    $html .= '</li>';

    }
    }

    continue;
    }

    }

    // @var Forminator_Form_Field_Model $form_field
    $field_type = $form_field->__get( 'type' );
    if ( 'section' === $field_type ) {
    $value = $form_field->__get( 'section_title' );
    if( ! empty( $value ) ) {
    $html .= '</ol>';
    $html .= '<h4><b>' . $value . '</b></h4>';
    $html .= '<ol>';
    }
    } elseif ( 'html' === $field_type ) {
    $label = $form_field->get_label_for_entry();
    $value = $form_field->__get( 'variations' );
    $content = forminator_replace_variables( $value, $custom_form->id, $data['current_url'] );
    $html .= '</ol>';
    $html .= '<h4><b>' . $label . '</b></h4>';
    $html .= $content;
    $html .= '<ol>';

    } else {
    if ( in_array( $field_type, $ignored_field_types, true ) ) {
    continue;
    }
    $value = render_entry( $entry, $form_field->slug );
    if( ! empty( $value ) ) {
    $html .= '<li>';
    $label = $form_field->get_label_for_entry();

    if ( ! empty( $label ) ) {
    $html .= '<b>' . $label . '</b><br/>';
    }
    $html .= $value . '<br/>';
    $html .= '</li>';
    }
    }
    }
    $html .= '</ol><br/>';

    return $html;
    }, 20, 5 );

    Please let me know if that works on your end. Have a great day ahead.

    Regards,

    Prathamesh

  • Panos
    • SLS

    Hi F404 !

    In case the snippet is still not working for you, could you share admin and ftp access so we could have a closer look there and save some time? You can send that privately through our contact form: https://premium.wpmudev.org/contact/#i-have-a-different-question

    Send in:Subject: “Attn: Panos Lyrakis”

    – Admin login:

    Admin username

    Admin password

    Login url

    – FTP credentials

    host

    username

    password

    (and port if required)

    – link back to this thread for reference

    Thanks!

  • F404
    • Flash Drive

    Hello
    This solution can not work when I need set list of emails. In select value I can put one email but if I put list of email (email1@test.com, email11111@test.com) it did not works.

    Can we make snippet like this :
    If in forms I have Select value : “Option 1″,”Option 2″ ,”Option 3”
    I want create snippet, if user select:
    Option 1 = email1@test.com, email11111@test.com, email111111@test.com; <— send notfictions on this emails.
    if
    Option 2 = email2@test.com, email222@test.com, email222222@test.com; <— send notfictions on this

  • Panos
    • SLS

    Hi F404 ,

    Makes sense since the emails are visible!

    I’m including 2 different snippets, one is for setting the emails for the Admin Email and second one is for the Confirmation Emails.

    Snippet for Admin Emails:

    
    function wpmudev_forminator_get_admin_email_recipients( $mail_args ) {
    
    	remove_filter( 'wp_mail', 'wpmudev_forminator_get_admin_email_recipients' );
    
    	if ( ! isset( $_REQUEST['wpmudev_forminator_entry'] ) ) {
    		return $mail_args;
    	}
    
    	$entry = $_REQUEST['wpmudev_forminator_entry'];
    	unset( $_REQUEST['wpmudev_forminator_entry'] );
    
    	$form_emails = array(
    
    		// For form id <code>4412</code>
    		4412 => array(
    			// If selection is <code>select-1</code>
    			'select-1' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		),
    
    		// For form id <code>6381</code>
    		6381 => array(
    			// If selection is <code>select-42</code>
    			'select-42' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		),
    
    	);	
    
    	$form_ids = array_keys( $form_emails );
    	$form_id = $entry->form_id;
    
    	if ( ! in_array( $form_id, $form_ids ) || empty( $entry->meta_data ) ) {
    		return $email;
    	}
    
    	$field_keys = array_keys( $form_emails[ $form_id ] );
    
    	foreach ( array_keys( $form_emails[ $form_id ] ) as $field_key ) {
    
    		if ( ! isset( $entry->meta_data[ $field_key ] ) ) {
    			continue;
    		}
    
    		if ( $value = $entry->meta_data[ $field_key ][ 'value' ] ) {
    
    			if ( $new_emails = $form_emails[ $form_id ][ $field_key ][ $value ] ) {
    				$mail_args[ 'to' ] = $new_emails;				
    			}
    			return $mail_args;
    
    		}
    
    	}
    
    	return $mail_args;
    
    }
    
    add_action( 'forminator_custom_form_mail_before_send_mail', function( $Front_email_obj, $custom_form, $data, $entry ){
    
    	$_REQUEST['wpmudev_forminator_entry'] = $entry;
    	add_filter( 'wp_mail', 'wpmudev_forminator_get_admin_email_recipients' );
    
    }, 20, 4 );
    

    Here is the snippet for the Confirmation Emails:

    
    add_filter( 'forminator_get_user_email_recipients', function( $email, $setting, $data, $custom_form, $entry ){
    
    	$form_emails = array(
    
    		// For form id <code>4412</code>
    		4412 => array(
    			// If selection field is <code>select-1</code>
    			'select-1' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		),
    
    		// For form id <code>6381</code>
    		6381 => array(
    			// If selection is field <code>select-42</code>
    			'select-42' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		),
    
    	);
    
    	$form_ids = array_keys( $form_emails );
    	$form_id = $entry->form_id;
    
    	if ( ! in_array( $form_id, $form_ids ) || empty( $entry->meta_data ) ) {
    		return $email;
    	}
    
    	$field_keys = array_keys( $form_emails[ $form_id ] );
    
    	foreach ( array_keys( $form_emails[ $form_id ] ) as $field_key ) {
    
    		if ( ! isset( $entry->meta_data[ $field_key ] ) ) {
    			continue;
    		}
    
    		if ( $value = $entry->meta_data[ $field_key ][ 'value' ] ) {
    
    			if ( $new_emails = $form_emails[ $form_id ][ $field_key ][ $value ] ) {
    				return $new_emails;
    
    			} else {
    				return $email;
    			}
    
    		}
    
    	}
    
    	return $email;
    }, 20, 5 );
    

    What you need to change in both snippet is the values in the $form_emails array. In the snippet there are comments that should indicate what each value represents. In the sample code it contains information for 2 form ids:

    
    // For form id <code>4412</code>
    		4412 => array(
    			// If selection field is <code>select-1</code>
    			'select-1' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		),
    
    		// For form id <code>6381</code>
    		6381 => array(
    			// If selection is field <code>select-42</code>
    			'select-42' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		),
    

    If you only want to do that for one form, you can change the array to:

    
    
    	$form_emails = array(
    
    		// For form id <code>4412</code>
    		4412 => array(
    			// If selection field is <code>select-1</code>
    			'select-1' => array(
    				// If <code>one</code> is selected 
    				'one' => array(  'email1@test.com', 'email111@test.com', 'email111111@test.com' ),
    				// If <code>two</code> is selected 
    				'two' => array(  'email2@test.com', 'email222@test.com', 'email222222@test.com' ),
    				// If <code>three</code> is selected 
    				'three' => array(  'email3@test.com', 'email333@test.com', 'email333333@test.com' ),
    			),
    			
    
    		)
    
    	);
    

    and then update the form id, field id and the emails per selection.

    In case this is confusing you can share the exact values for the form id, field and the emails per selected value so I could update that snippet for you.

    I would strongly recommend to first test this snippet(s) in a staging/testing site before moving to production site.

    Lind regards!

  • Mukul Chawla
    • Product Designer

    Hey F404

    Hope you are doing well.

    I just wanted to inform you that the feature you have been waiting for – Email routing/Conditional emails is very close to release. We have posted a beta of Forminator 1.10(which includes this feature) on the test center. If you are interested, I’d like to invite you to give that beta a spin and provide any valuable feedback you may have.

    Test Center link: https://premium.wpmudev.org/forums/topic/forminator-1-10-hubspot-ticketing-email-routing-new-pagination-flow-pre-filling-forms-and-more/

    Regards,
    Mukul Chawla

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.