Skip to content

Instantly share code, notes, and snippets.

@stefanbc
Created February 20, 2014 07:06
Show Gist options
  • Save stefanbc/9108390 to your computer and use it in GitHub Desktop.
Save stefanbc/9108390 to your computer and use it in GitHub Desktop.
Custom Functions for Contact Form 7
<?php
// Get date from Contact Form 7 before email send
add_action("wpcf7_before_send_mail", "wpcf7_save_data");
function wpcf7_save_data(&$wpcf7_data) {
// Here is the variable where the data are stored!
$user_nume = $wpcf7_data->posted_data['user_nume'];
$user_email = $wpcf7_data->posted_data['user_email'];
// Set the cookies
setcookie('os_username', $user_nume, time() + (10*365*24*60*60));
setcookie('os_useremail', $user_email, time() + (10*365*24*60*60));
// If you want to skip mailing the data, you can do it...
//$wpcf7_data->skip_mail = true;
}
// Populate Contact Form 7 hidden fields
add_filter('wpcf7_hidden_field_value_hidden_nume', 'wpcf7_hidden_field_add_query_nume');
function wpcf7_hidden_field_add_query_nume($value = '') {
if ($_COOKIE['os_username']) {
return $_COOKIE['os_username'];
}
return $value;
}
add_filter('wpcf7_hidden_field_value_hidden_email', 'wpcf7_hidden_field_add_query_email');
function wpcf7_hidden_field_add_query_email($value = '') {
if ($_COOKIE['os_useremail']) {
return $_COOKIE['os_useremail'];
}
return $value;
}
// Do custom shortcuts in a contact form
add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );
return $form;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment