• So I have a function written that takes submitted CF7 form data and parses it into user metadata. I have tested it and it works on single contact forms with no issue. The problem I’m having is that at the end of the multistep form it’s not submitting.

    Here’s the basic function:

    //Onboard Data Export
    add_action( 'wpcf7_before_send_mail', 'vbg_user_onboard' );
    function vbg_user_onboard( $contact_form ){
    	if (!isset($contact_form->posted_data) && class_exists('WPCF7_Submission')) {
    		$log .= 'posted data set and class exists!\n';
    		$submission = WPCF7_Submission::get_instance();
    		$current_user = wp_get_current_user();
    		$user_id = $current_user->ID;
    		if ($submission) {
    			$log .= 'submission exists!\n';
    			$formdata = $submission->get_posted_data();
    		}
    		if( !empty($formdata['past-claim'])){
    			//parse user data
    			$user_email = $formdata['user-email'];
    			$user_filed_before = $formdata['past-claim'];
    
    			//User Meta
    			$user_meta = array(
    				'filed_before' => $user_filed_before,
    			);
    
    			//Set metadata        
    			update_user_meta( $user_id, "filed_before", $user_meta['filed_before'] );
    		} 
    	}//end
    }

    Is there a specific way that data is handled in these forms? How do I get the posted data? The emails seem to send just fine with no errors in passing the data so it must be there.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter starfiredev

    (@starfiredev)

    I spent a good bit of today working with it and I have some updated code. I changed the method a bit to instead pull the results from the session cookie. While it does store it in the array $formdata successfully, it doesn’t seem to write to the user_meta at all.

    ‘add_action( ‘wpcf7_before_send_mail’, ‘vbg_user_onboard’ );
    function vbg_user_onboard(){

    if(!isset($_COOKIE[‘cf7msm_posted_data’])) {
    //
    } else{
    $current_user = wp_get_current_user();
    $user_id = $current_user->ID;
    $cookie_data = $_COOKIE[‘cf7msm_posted_data’];
    $cookie_data = stripslashes($cookie_data);
    $formdata = (array) json_decode($cookie_data);

    //parse user data
    $user_email = $formdata[‘user-email’];
    $user_filed_before = $formdata[‘past-claim’];
    }
    }

    This is a very stripped down version for example purposes. I have about 20 or so variables that get passed through the form. It doesn’t exceed the 4kb cookie limit.

    I also had some more statements to make sure it only submitted on the final form but I needed to strip things down for testing.

    If there’s any help you can still offer it would be appreciated.

    • This reply was modified 4 years, 10 months ago by starfiredev.
    Plugin Author webheadcoder

    (@webheadllc)

    Hi,

    That’s one way to get the posted data, another way is to use the wpcf7_posted_data filter.

    As far as saving to user meta I’m not sure what might be wrong and is beyond the scope of this plugin. Just make sure that part of your code is reached and the user id and the value your saving is not empty.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to capture form data with custom function, not passing data’ is closed to new replies.