Skip to content

Instantly share code, notes, and snippets.

@joviczarko
Created April 13, 2018 08:52
Show Gist options
  • Save joviczarko/724e960b0ba5d3e254cb283e45550c65 to your computer and use it in GitHub Desktop.
Save joviczarko/724e960b0ba5d3e254cb283e45550c65 to your computer and use it in GitHub Desktop.
Sending Contact Form 7 data to another system
//Submitting of the form
function cf7_sending_func( $contact_form ) {
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
$form_params = array(
'email' => $posted_data['your-email'],
'name' => $posted_data['your-name'],
'phone' => $posted_data['your-phone'],
);
//Print in error log if enabled to check if data is passed
//error_log( print_r($form_params, true) );
//Calling the function that communicates with other system. ž
//It is better to be in separate function if you have multiple forms
ApiSendDataToSystem( $form_params );
return true;
}
//add_action( 'wpcf7_before_send_mail', 'cf7_sending_func', 10, 1 ); //Alternative action to do before sending mail
add_action( 'wpcf7_mail_sent', 'cf7_sending_func', 10, 1 ); // To call function when sending mail
function ApiSendDataToSystem( $form_params ) {
// HERE GOES THE CODE THAT COMMUNICATE TO OTHER SYSTEM API
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment