Contact Form 7 – Prevent Email Sending When Checkbox is Unchecked
-
Hi Team,
I’m using Contact Form 7 version 5.9.8, and I want to prevent the form from sending emails when a specific checkbox is unchecked. I attempted the following code, but it is not working as expected:
function prevent_email_for_specific_form($contact_form)
{
$target_form_id = '1238782';
if ($contact_form->id() !== $target_form_id) {
return;
}
$submission = WPCF7_Submission::get_instance();
if (!$submission) return;
$data = $submission->get_posted_data();
if (empty($data['consent'])) {
add_filter('wpcf7_skip_mail', '__return_true');
}
}
add_action('wpcf7_before_send_mail', 'prevent_email_for_specific_form', 10, 1);Could you please help me identify what might be wrong and suggest a working solution?
Thanks in advance!
- You must be logged in to reply to this topic.