wpcf7_mail_sent infinite loop
-
I created a couple of functions to trigger once the contact form is sent. This function generates a unique reference number and saves it on a database table together with a couple of posted data. The form successfully sends a mail and a database row is also added successfully however there is a weird occurrence on the form page, it does not go past beyond the loading icon and does not show up the ‘sent successfully’ message. Aside from that, the page does not get redirected to the thank you page which I set using on_sent_ok.
add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );function gen_ref( $ref_name = 'X X') {
$int_ren_name = split(" ",preg_replace('/\s\s+/', ' ', trim($ref_name)));
$fname = strtoupper($int_ren_name[0]);
$sname = (count($int_ren_name)>1) ? strtoupper($int_ren_name[1]) : $fname{1};return date("U").$fname{0}.$sname{0};
}function your_wpcf7_mail_sent_function( $contact_form ) {
global $wpdb;
$title = $contact_form->title;
$posted_data = $contact_form->posted_data;if ( 'Contact Us Form' == $title ) {
$name = $posted_data['name'];
$surname = $posted_data['surname'];
$email = $posted_data['email'];
$ref_name = $name." ".$surname;$referenceNumber = gen_ref($ref_name);
$sql = $wpdb->prepare("INSERT INTO
wp_formdata
(reference_id
,name
,surname
,email
) VALUES (%d,%s,%s,%s)”, $referenceNumber, $name, $surname, $email);$wpdb->query($sql);
}
}
- The topic ‘wpcf7_mail_sent infinite loop’ is closed to new replies.