1

#I am facing issue with contact Form 7 Multi Step Form plugin 4.0.8 version , with this i am unable to go to next step after filling the first form, it is submitting with successfull message.

I am getting Undefined variable: curr_step in F:\websites\websitename\wp-content\plugins\contact-form-7-multi-step-module\cf7msm.php on line 451

{
    $curr_step = '';
    $last_step = '';
    $is_last_step = false;
    if ( empty($cf7_posted_data['cf7msm-step']) && empty($cf7_posted_data['cf7msm_options']) ) {
        return $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];
            $is_last_step = $curr_step == $last_step;
        }
    
    }
    
    if ( !empty($curr_step) && !empty($last_step) ) {
        //for step-restricted back button
        $prev_urls = cf7msm_get( 'cf7msm_prev_urls' );
        if ( empty($prev_urls) ) {
            $prev_urls = array();
        }
        //old 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
        $prev_urls[$curr_step + 1 . '-' . $last_step] = cf7msm_current_url();
        cf7msm_set( 'cf7msm_prev_urls', $prev_urls );
    }
    
    // TODO:  set curr_step and last_step for new tag when implemented.
    
    if ( !empty($cf7_posted_data['cf7msm_options']) ) {
        $options = json_decode( stripslashes( $cf7_posted_data['cf7msm_options'] ), true );
        $is_last_step = !empty($options['last_step']);
    }
    
    $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();
        }
        //remove empty [form] tags from posted_data so $prev_data can be stored.
        $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 );
                }
            }
        
        }
        //if original key is set and not free text, remove free text to reflect posted data.
        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] );
            }
        }
        $cf7_posted_data = array_merge( $prev_data, $cf7_posted_data );
    }
    
    return $cf7_posted_data;
}

add_filter( 'wpcf7_posted_data', 'cf7msm_add_other_steps_filter', 9 );
/**
 * If use cookies and not the last step, store the values here after it's been validated.
 */
function cf7msm_store_data_steps()
{
    $use_cookies = true;
    
    if ( $use_cookies ) {
        $cf7_posted_data = WPCF7_Submission::get_instance()->get_posted_data();
        $is_last_step = false;
        
        if ( !empty($cf7_posted_data['cf7msm_options']) ) {
            $options = json_decode( stripslashes( $cf7_posted_data['cf7msm_options'] ), true );
            $is_last_step = !empty($options['last_step']);
        }
        
        
        if ( !$is_last_step ) {
            // don't track big cookies on last step bc submitting on the last step doesn't use the cookie.
            cf7msm_track_big_cookie( $curr_step, $cf7_posted_data );
            cf7msm_set( 'cf7msm_posted_data', $cf7_posted_data );
        }
    
    }

}

add_action( 'wpcf7_before_send_mail', 'cf7msm_store_data_steps' );```


   
vinay
  • 11
  • 1
  • The `cf7msm_store_data_steps` function has no knowledge about `$curr_step`. – Jeto Oct 24 '20 at 07:37
  • Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Jeto Oct 24 '20 at 07:37

0 Answers0