0

I'm trying to feed a repeater field with the values submitted via a registration form (I'm using Contact Forms 7).

When debugging the array of values passed to the "add_row" function, everything seems to be well introduced, but there must be an error because nothing happens, and the repeater is not updated. Actually, the function add_row seems to return false, but I cannot find the error...

So far this is the code that I'm using:

add_action( 'wpcf7_before_send_mail', 'mafsuf_wpcf7_update_repeater_field' );
function mafsuf_wpcf7_update_repeater_field($wpcf7) {
 
        //Data sent by WPCF7
        $submission = WPCF7_Submission::get_instance();
        
        //Get post ID
        $event_post_id = $submission->get_meta( 'container_post_id' );

        //Get other values
        $data = $submission->get_posted_data();
        $asist_date = date('Ymd');
        $asist_org = $data['ev_soci_id'];
        $asist_name = $data['ev_nom'] . ' ' . $data['ev_cognoms'];
        $asist_notes = $data['ev_carrec'];

        //ADD ROW TO REPEATER FIELD BY KEY
        //field_61704a5a97d56 is the repeater's field key "assistance_list"
        $field_key = 'field_61704a5a97d56';
        $row = array(
            'field_61704bb597d57' => $asist_date,   //'asist_date'
            'field_61704d4597d59' => $asist_org,    //'asist_org'
            'field_61704cd797d58' => $asist_name,   //'asist_name'
            'field_61704e4297d5a' => $asist_notes,  //'asist_notes'
        );
        
        add_row( $field_key, $row, $event_post_id );

        //For DEBUG Purposes
        error_log(print_r($row,true),3,__DIR__."/../log.txt");
        //When checking the log file I confirm that $row has the correct format

        //Not sure that "return" is necessary because we are not changing $wpcf7 at all
        return $wpcf7;
        
}

Any thoughts? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.