我具有cf7格式,我想将数据保存在sql和其他api中,但是在下一步中,我想重定向我的用户。我不知道该如何捕捉事件,因为我的php保存脚本会挂起所有表格。在所有时间,我都看到加载程序,单击“发送”后。
以及我如何只能将此脚本用于一种形式。如果formid =='id',我尝试添加操作,但对我不起作用。
对不起,我的英语,但是我是波兰洋葱。 :)
function contactform7_before_send_mail( $form_to_DB ) {
//set your db details
global $wpdb;
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB )
$formData = $form_to_DB->get_posted_data();
$name = $formData['your-name'];
$surname = $formData['your-surname'];
$email = $formData['your-email'];
$phone = $formData['telefon'];
$pesel = $formData['pesel'];
/************* Insert in wordpress database ***********/
$wpdb->insert( 'wniosek', array( 'name' =>$name, 'surname' =>$surname, 'email' =>$email, 'phone' =>$phone, 'pesel' =>$pesel), array( '%s' ) );
/************ For Php Mysql Database (Create connection first) ********/
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (title)
VALUES ($title)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
remove_all_filters ('wpcf7_before_send_mail');
add_action('wpcf7_before_send_mail', 'contactform7_before_send_mail');