IP block in Contact form 7 / database
-
Hello people,
I hope someone can help me out here. I’m using contact form 7 + EBD ( email before download) to let people submit a form before downloading something.
I’m using this code to block duplicate emails.function is_already_submitted($formName, $fieldName, $fieldValue) { require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php'); $exp = new CFDBFormIterator(); $atts = array(); $atts['show'] = $fieldName; $atts['filter'] = "$fieldName=$fieldValue"; $atts['unbuffered'] = 'true'; $exp->export($formName, $atts); $found = false; while ($row = $exp->nextRow()) { $found = true; } return $found; } /** * @param $result WPCF7_Validation * @param $tag array * @return WPCF7_Validation */ function my_validate_email($result, $tag) { $formName = 'DownloadForm'; // Change to name of the form containing this field $fieldName = 'ipadres'; // Change to your form's unique field name $errorMessage = 'Je hebt al een gratis rapport aangevraagd met deze IP'; // Change to your error message $name = $tag['name']; if ($name == $fieldName) { if (is_already_submitted($formName, $fieldName, $_POST[$name])) { $result->invalidate($tag, $errorMessage); } } return $result; } // use the next line if your field is a **required email** field on your form add_filter('wpcf7_validate_email*', 'my_validate_email', 10, 2);
I also want to block/prevent duplicate IP adresses to download.
I figured I would just need to rename the “your-email” in the code to labelname of the IP, however the name is “Submitted From”. The code I’m using to block the duplicate emails is working. But my revised version for IP adresses isn’t working.Could someone help me figure this out?
source of the code https://cfdbplugin.com/?page_id=904
- The topic ‘IP block in Contact form 7 / database’ is closed to new replies.