Two hooks are not working together on contact form 7
-
I am trying to run two CF7 hooks when user submits form. First check for validation, if user exist in database or not. If user have already registered, if will throw validation error.If user is new, email will be sent to 3 other people. But when user is new, cf7 loader goes into infinite mode and keep loading. Nothing happens. I think that after wpcf7_validate, its not giving control to wpcf7_before_send_mail hook. wpcf7_validate is working when user is existed and throw notice that user existed.
add_filter( 'wpcf7_validate', 'email_already_in_db', 10, 2 ); if (!function_exists("email_already_in_db")) { function email_already_in_db ( $result, $tags ) { /* here I check if email already existed in db, if yes , then throw validation error saying User already existed */ /*I run mysql query using wpdb*/ if($wpdb->num_rows > 0){ $result->invalidate('your-email', 'Invalid email'); return $result; } } } add_action('wpcf7_before_send_mail', 'register_save_cf7_data'); if (!function_exists("register_save_cf7_data")) { /*If user is new then this will send email*/ function register_save_cf7_data( $contact_form){ /*I retrieve all cf7 data and send email */ $to = $youremail; $subject = 'The subject'; $body = $str1; if(wp_mail( $to, $subject, $body )){ echo ""; } } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Two hooks are not working together on contact form 7’ is closed to new replies.