• czhao1009

    (@czhao1009)


    Hello,

    I’m adding custom actions for when the form is submitted (with repeatable fields), but not sure how to retrieve the repeatable fields from the $_POST. Is there a way to loop over the field groups without knowing the total number of groups?

    If I have this in the form:

    
    [field_group product-list]
        <label> Product Description (required)
            [text* product-description] </label>
    [/field_group]
    

    How should I loop over all the new entries user has added in PHP:

    
    function action_wpcf7_submit( $cf7 ) {
    
        // loop over entries of product-list?
    }
    add_action( 'wpcf7_before_send_mail', 'action_wpcf7_submit'); 
    

    Thank you,
    Chen

Viewing 1 replies (of 1 total)
  • Here’s how I did it:

    function action_wpcf7_mail_sent($contact_form)
    {
        $submission = WPCF7_Submission::get_instance();
        if ($submission) {
            $posted_data = $submission->get_posted_data();
    
            $num = $posted_data['_wpcf7_groups_count']['my_field_group_name'];
            for ($i = 1; $i <= $num; $i++){
                echo $posted_data['my_repeater_field_name__'.$i];
            }
        }
    }
    add_action( 'wpcf7_mail_sent', 'action_wpcf7_mail_sent', 10, 1 );
Viewing 1 replies (of 1 total)
  • The topic ‘Access repeated fields in PHP hook’ is closed to new replies.