wp-content/plugins/contact-form-7-multi-step-module/cf7msm.php
/**
 * Handle a multi-step cf7 form for cf7 3.9+
 */
Handle a multi-step cf7 form for cf7 3.9+
Handle a multi - step cf7 form for cf7 3 . 9 +
function cf7msm_store_data_steps_filter( $cf7_posted_data )
{
    if ( isset( $cf7_posted_data['cf7msm-step'] ) ) {
        if ( preg_match( '/(\\d+)-(\\d+)/', $cf7_posted_data['cf7msm-step'], $matches ) ) {
            $curr_step = $matches[1];
            $last_step = $matches[2];
        }
        $prev_urls = cf7msm_get( 'cf7msm_prev_urls' );
        if ( empty($prev_urls) ) {
            $prev_urls = array();
        }
        $prev_urls[$curr_step + 1 . '-' . $last_step] = cf7msm_current_url();
        cf7msm_set( 'cf7msm_prev_urls', $prev_urls );
        $use_cookies = true;
        if ( !empty($cf7_posted_data['cf7msm-no-ss']) || $use_cookies ) {
            $prev_data = cf7msm_get( 'cf7msm_posted_data', '' );
            if ( !is_array( $prev_data ) ) {
                $prev_data = array();
            }
            $fes = wpcf7_scan_form_tags();
            foreach ( $fes as $fe ) {
                if ( empty($fe['name']) || $fe['type'] != 'form' && $fe['type'] != 'multiform' ) {
                    continue;
                }
                unset( $cf7_posted_data[$fe['name']] );
            }
            $free_text_keys = array();
            foreach ( $prev_data as $key => $value ) {
                if ( strpos( $key, CF7MSM_FREE_TEXT_PREFIX_RADIO ) === 0 ) {
                    $free_text_keys[$key] = str_replace( CF7MSM_FREE_TEXT_PREFIX_RADIO, '', $key );
                } else {
                    if ( strpos( $key, CF7MSM_FREE_TEXT_PREFIX_CHECKBOX ) === 0 ) {
                        $free_text_keys[$key] = str_replace( CF7MSM_FREE_TEXT_PREFIX_CHECKBOX, '', $key );
                    }
                }
            }
            foreach ( $free_text_keys as $free_text_key => $original_key ) {
                if ( isset( $cf7_posted_data[$original_key] ) && !isset( $cf7_posted_data[$free_text_key] ) ) {
                    unset( $prev_data[$free_text_key] );
                }
            }
            if ( $curr_step != $last_step ) {
                $posted_data = array_merge( $prev_data, $cf7_posted_data );
                cf7msm_set( 'cf7msm_posted_data', $posted_data );
            } else {
                $cf7_posted_data = array_merge( $prev_data, $cf7_posted_data );
            }
        }
    }
    return $cf7_posted_data;
}
function cf7msm_store_data_steps_filter ( $ cf7_posted_data ) { if ( isset ( $ cf7_posted_data [ 'cf7msm-step' ] ) ) { if ( preg_match ( '/(\\d+)-(\\d+)/' , $ cf7_posted_data [ 'cf7msm-step' ] , $ matches ) ) { $ curr_step = $ matches [ 1 ] ; $ last_step = $ matches [ 2 ] ; } $ prev_urls = cf7msm_get ( 'cf7msm_prev_urls' ) ; if ( empty ( $ prev_urls ) ) { $ prev_urls = array ( ) ; } $ prev_urls [ $ curr_step + 1 . '-' . $ last_step ] = cf7msm_current_url ( ) ; cf7msm_set ( 'cf7msm_prev_urls' , $ prev_urls ) ; $ use_cookies = true ; if ( ! empty ( $ cf7_posted_data [ 'cf7msm-no-ss' ] ) || $ use_cookies ) { $ prev_data = cf7msm_get ( 'cf7msm_posted_data' , '' ) ; if ( ! is_array ( $ prev_data ) ) { $ prev_data = array ( ) ; } $ fes = wpcf7_scan_form_tags ( ) ; foreach ( $ fes as $ fe ) { if ( empty ( $ fe [ 'name' ] ) || $ fe [ 'type' ] != 'form' && $ fe [ 'type' ] != 'multiform' ) { continue ; } unset ( $ cf7_posted_data [ $ fe [ 'name' ] ] ) ; } $ free_text_keys = array ( ) ; foreach ( $ prev_data as $ key => $ value ) { if ( strpos ( $ key , CF7MSM_FREE_TEXT_PREFIX_RADIO ) === 0 ) { $ free_text_keys [ $ key ] = str_replace ( CF7MSM_FREE_TEXT_PREFIX_RADIO , '' , $ key ) ; } else { if ( strpos ( $ key , CF7MSM_FREE_TEXT_PREFIX_CHECKBOX ) === 0 ) { $ free_text_keys [ $ key ] = str_replace ( CF7MSM_FREE_TEXT_PREFIX_CHECKBOX , '' , $ key ) ; } } } foreach ( $ free_text_keys as $ free_text_key => $ original_key ) { if ( isset ( $ cf7_posted_data [ $ original_key ] ) && ! isset ( $ cf7_posted_data [ $ free_text_key ] ) ) { unset ( $ prev_data [ $ free_text_key ] ) ; } } if ( $ curr_step != $ last_step ) { $ posted_data = array_merge ( $ prev_data , $ cf7_posted_data ) ; cf7msm_set ( 'cf7msm_posted_data' , $ posted_data ) ; } else { $ cf7_posted_data = array_merge ( $ prev_data , $ cf7_posted_data ) ; } } } return $ cf7_posted_data ; }
Handle a multi-step cf7 form for cf7 3.9+
Handle a multi - step cf7 form for cf7 3 . 9 +
//for back button //example: // on step 1, //    prev url {"2-3":"page-2"} will be set. //    back button is pressed, key "1-3" is looked up and returns undefined // on step 2, //    prev url {"3-3":"page-2"} will be set. //    back button is pressed, key "2-3" is looked up and returns "page-1" // on step 3, //    prev url {"4-3":"page-3"} will be set. - not used //    back button is pressed, key "3-3" is looked up and returns "page-2" // step //remove empty [form] tags from posted_data so $prev_data can be stored. //if original key is set and not free text, remove free text to reflect posted data.