How to include field groups in email sent after form submission

Support MB Frontend Submission How to include field groups in email sent after form submissionResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33808
    synchrosynchro
    Participant

    OK, so I have a form with like 8 field groups with 3-4 sub-fields in each.

    I'd like to send an email after form submission to admin including all those groups and sub-fields values and labels.

    But I can't do that. I can include regular fields values (value 1 and 2 in my code), Value 3 is what gives me trouble.

    This is what I'm trying to use:

    add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
        if ( 'application_form' === $config['id'] ) {
                $value1 = empty( $_POST['text_8qziiie3rt6'] ) ? null : $_POST['text_8qziiie3rt6'];
                $value2 = empty( $_POST['text_text'] ) ? null : $_POST['text_text'];
                $value3 = $group = rwmb_meta( 'contact', '', $post_id );
                        $t1 = $group['contact_1'];
                        $t2 = $group['contact_2'];
                $to = '[email protected]';
                $subject = 'New application';
                $body = '<div class="mail-body" style="color:#ccc;">Your application details: ' . '' . '<div>' . 'Text 1:' . $value1 . '</div>' . '<div>' . 'Text 2:' . $value2 . '</div>' . '<div>' . 'Text 3:' . $value3 . '</div>' . 'This is it!</div>';
                $headers = array( 'Content-Type: text/html; charset=UTF-8' );
                
                wp_mail( $to, $subject, $body, $headers );
    
                wp_safe_redirect( 'thank-you' );
            
            die;
        }
    }, 10, 2 );

    Also, is there a way to include all of those fields at once, like the entire form with the fields' values and names? I got around 30 fields....

    Thank you for all your help, you're awesome.

    #33833
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can just use the global variable $_POST to get any field value when submitting the post. For example:

    $group = $_POST['group_id'];
    $subfield1 = $group['subfield1'];
    $subfield2 = $group['subfield2'];
    #34513
    synchrosynchro
    Participant

    Sorry for late reply. It works of course, thank you.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.