Support » Plugin: Contact Form 7 » PHP after form submit?

  • Resolved OC2PS

    (@sooskriszta)


    I am trying to hook some functions after contact form submission. I have added this into the functions.php:

    add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );
    
    function your_wpcf7_mail_sent_function( $contact_form ) {
    	$title = $contact_form->title;
    	$posted_data = $contact_form->posted_data;
    
    	if ( 'Free Evaluation' == $title ) {
    
    		$Function = "CreateContact";
    
                    $FullName = $posted_data['your-name'];
    
                    $Email = array(
                        0=>array(
                            "Text"=>$posted_data['your-email'],
                            "Type"=>"Personal"
                        )
                    );
    
                    $Phone = array(
                        0=>array(
                            "Text"=>$posted_data['tel-424'],
                            "Type"=>"Mobile"
                        )
                    );
    
                    $CustomFields = array(
                        "Location (Required)"=>"Singapore"
                    );
    
                    $Parameters = array(
                        "FullName"=>$FullName,
                        "Email"=>$Email,
                        "Phone"=>$Phone,
                        "CustomFields"=>$CustomFields
                    );
    
    		$Result = CallAPI($Function, $Parameters);
    
    	}
    }

    The CallAPI function is also defined in functions.php

    However, it seems $posted_data['your-name']; etc are not grabbing the form’s submitted values for me.

    https://wordpress.org/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
  • Thread Starter OC2PS

    (@sooskriszta)

    Seems I was trying an old method. Replaced
    $posted_data = $contact_form->posted_data;
    with

    $submission = WPCF7_Submission::get_instance();
    $posted_data = $submission->get_posted_data();

Viewing 1 replies (of 1 total)
  • The topic ‘PHP after form submit?’ is closed to new replies.