Last active
April 20, 2019 04:32
-
-
Save yeriepiscesa/0acde5b4876dc61730e8f3c41defe49f to your computer and use it in GitHub Desktop.
Proses simpan ke database - https://solusipress.com/menyimpan-data-contact-form-7-pada-custom-table/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpcf7_contacts_save_to_db( $cf, $result ) { | |
$submission = WPCF7_Submission::get_instance(); | |
if ( ! $submission || ! $posted_data = $submission->get_posted_data() ) { | |
return; | |
} | |
if( $result['status'] == 'mail_sent' ) { | |
global $wpdb; | |
if( !is_numeric( $posted_data['province'] ) ) $posted_data['province'] = null; | |
if( !is_numeric( $posted_data['regency'] ) ) $posted_data['regency'] = null; | |
if( !is_numeric( $posted_data['district'] ) ) $posted_data['district'] = null; | |
if( !is_numeric( $posted_data['village'] ) ) $posted_data['village'] = null; | |
$values = array( | |
'full_name' => $posted_data['your-name'], | |
'email' => $posted_data['your-email'], | |
'address' => $posted_data['your-address'], | |
'province_id' => $posted_data['province'], | |
'regency_id' => $posted_data['regency'], | |
'district_id' => $posted_data['district'], | |
'village_id' => $posted_data['village'], | |
'subject' => $posted_data['your-subject'], | |
'message' => $posted_data['your-message'], | |
'ip_address' => $_SERVER['REMOTE_ADDR'], | |
'submit_date' => date("Y-m-d H:i:s"), | |
'user_agent' => $_SERVER['HTTP_USER_AGENT'] | |
); | |
$inserted = $wpdb->insert( | |
$wpdb->prefix.'contacts', | |
$values, | |
array( | |
'%s', '%s', '%s', | |
'%s', '%s', '%s', '%s', | |
'%s', '%s', | |
'%s', '%s', '%s' | |
) | |
); | |
} | |
} | |
add_action( 'wpcf7_submit', 'wpcf7_contacts_save_to_db', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment