• What’s the best way to hook the form submit and access the data that was submitted?

    I’ve tried hooking using add_action-

    wpcf7_submit
    wpcf7_before_send_mail
    wpcf7_form_response_output

    and I can get the form itself when it was submitted, but not the data that the user inputted into the form.

    Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Did you find an answer to this as I require the same info?

    Cheers,
    Tristan

    Hoping this will help someone trying to learn everything at once, the following worked out for me. As a start use the following in your functions.php…

    
    add_action( 'wpcf7_mail_sent', 'do_my_work' ); //access after send
    
    if( ! function_exists( 'do_my_work' ) ) {
    	function do_my_work($cf7){ //contact form object passed in
    				
    		/* Use WPCF7_Submission object's get_posted_data() method to get it. */
    		$submission = WPCF7_Submission::get_instance();
    		$posted_data = $submission ? $submission->get_posted_data() : null; //get form data
    		if($posted_data){ 
    			$formName = $posted_data['your-name']; //get form field value
    			
    			// do something more
    			
    		}	
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hooking Form Submit’ is closed to new replies.