• Resolved jayahn4

    (@jayahn4)


    Hi there,

    I have a hidden field on my form, which I gave the value of an email address. I’ve set the Email notification so that it sends to the value of this hidden field. I can confirm in Mailhog that the email is sending.

    I’ve then added some code which dynamically changes the hidden input’s value using the value of an ACF field on the page

    add_filter( 'forminator_field_hidden_field_value', function( $value, $saved_value, $field ){
    
    ? ? $hidden_field_id = 'hidden-1';
    
    ? ? $post_id = get_the_ID();
    
    ? ? $advisor = get_field('new_home_advisor', $post_id);
    
    ? ? $email = get_field('email', $advisor->ID);
    
    ? ? if ( $hidden_field_id == $field[ 'element_id' ] ) {
    
    ? ? ? ? $value = $email;
    
    ? ? }
    
    ? ? return $value;
    
    }, 20, 3 );

    When I inspect the HTML, I can confirm that the new value is set, but submitting the form does not send the email.

    <input type="hidden" id="hidden-1_6594f1c7ad381" name="hidden-1" value="[email protected]">

    I wonder if changing the value alone isn’t enough? Does Forminator’s submit also make use of the id of this input in some way. If not, I wonder what I’m missing?

    Thanks,
    Jay

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @jayahn4

    Hope you’re doing well today! Thank you for the elaborate information.

    I have pinged our SLS team so that they can review your query and see what can be possible in this case. We will post an update here as soon as more information is available.

    Kind Regards,
    Saurabh

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @jayahn4

    Hope you’re doing well today!

    We have an update from our SLS team and they were able to review the snippet you added. In addition to the snippet you’ve added, can you please add the below snippet as well and check if it helps?

    add_filter( 'forminator_prepared_data', 'wpmudev_update_hidden_field_val_twin', 10, 2 );
    function wpmudev_update_hidden_field_val_twin( $prepared_data, $module_object ){
        $form_ids = array(6); //Please change the form ID
        if ( !in_array( $module_object->id, $form_ids ) ) {
            return $prepared_data;
        }
        
        foreach ( $prepared_data as $key => $value ) {
            if ( strpos( $key, 'hidden-1' ) !== false ) {
                $prepared_data[$key] = sanitize_text_field( $_POST[$key] );
            }
        }
    
        return $prepared_data;
    }
    
    add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_change_hidden_field_data_twin', 10, 3 );
    function wpmudev_change_hidden_field_data_twin( $entry, $module_id, $field_data_array ) {
        $form_ids = array(6); //Please change the form ID
         if ( !in_array( $module_id, $form_ids ) ) {
            return;
          }
        
        foreach ( $field_data_array as $key => $value ) {
            if ( strpos( $value['name'], 'hidden-1' ) !== false ) {
                Forminator_CForm_Front_Action::$info['field_data_array'][$key]['value'] = sanitize_text_field( $_POST[$value['name']] );
            }
        }
    
    }

    In the above snippet, you will need to update the existing form ID to your actual form ID in both the functions where it mentions –
    $form_ids = array(6); //Please change the form ID

    I would recommend you test the snippet on a staging/dev site so that it does not affect your live site.

    You can add the custom snippet as a mu-plugin inside the /wp-content/mu-plugins/ directory. You can refer to the below guide on how you can add a mu-plugin.

    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
    and

    Must Use Plugins

    Kind Regards,
    Saurabh

    Thread Starter jayahn4

    (@jayahn4)

    Hi Saurabh,

    Apologies for the late reply, as I have been on leave and just returned.

    The code has worked! I didn’t make use of a MU plugin and threw it into a functions file instead, but Mailhog confirms the email has sent.

    Thank you so much for your assistance here and Happy New Year!

    Jay

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Form does not send to dynamic email’ is closed to new replies.