Created
August 18, 2021 00:31
-
-
Save asllanmaciel/45cb2482eb4c1251ced2d652fe9599b2 to your computer and use it in GitHub Desktop.
Insert Contact Form 7 Submissions (WordPress) in External DB with PHP/MySQL
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 | |
//Use in theme functions.php | |
function save_db($cf7){ | |
$submission = WPCF7_Submission::get_instance(); | |
if($submission){ | |
$posted_data = $submission->get_posted_data(); | |
} | |
if($cf7->id() == 55){ | |
$con = mysqli_connect('localhost','root','','test_082021_2'); | |
$sql = "INSERT INTO clientes (nome,email) VALUES (?, ?)"; | |
if($stmt = mysqli_prepare($con, $sql)){ | |
mysqli_stmt_bind_param($stmt, 'ss', $param_nome, $param_email); | |
$param_nome = $posted_data['your-name']; | |
$param_email = $posted_data['your-email']; | |
if(mysqli_stmt_execute($stmt)){ | |
echo ''; | |
} | |
} | |
mysqli_stmt_close($stmt); | |
mysqli_close($con); | |
} | |
} | |
add_action('wpcf7_before_send_mail','save_db', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment