Created
September 1, 2011 23:50
-
-
Save jkudish/1187600 to your computer and use it in GitHub Desktop.
filters a Gravity Form to prevent submissions from an already submitted IP, good for spam prevention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* limit_submissions_by_ip() | |
* filters a Gravity Form to prevent submissions from an already submitted IP, good for spam prevention | |
* change the ID to match your form (ex: gform_pre_render_6) | |
* @param $form (array) the form | |
* @return $form (array) the filtered form | |
* @author Joachim Kudish <[email protected]> | |
* @link http://jkudish.com | |
*/ | |
add_action('gform_pre_render_1', 'limit_submissions_by_ip'); | |
function limit_submissions_by_ip($form){ | |
global $wpdb, $current_user; | |
$current_ip = $wpdb->escape($_SERVER['REMOTE_ADDR']); | |
$table_name = $wpdb->prefix.'rg_lead'; | |
$sql = $wpdb->prepare("SELECT * FROM {$table_name} WHERE form_id = %d AND ip = %s", $form['id'], $current_ip); | |
$last_submission = $wpdb->get_row($sql); | |
if($last_submission) : | |
?> | |
<style type="text/css"> | |
#gform_wrapper_<?php echo $form['id']; ?>, .post_content > h1, .post_content > p { display: none; } | |
</style> | |
<div class="error"> | |
Our records indicate that you've already submitted a registration from this IP address. </a> | |
</div> | |
<?php | |
$form = array(); // give it an empty array so that it doesn't generate the form at all [the whole goal is to keep spammers away after all] | |
endif; | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, is there any way i can limit access of site members to seeing form entries base of a field? I have a form and it has a city field, I want defined admins for every city whom can only see entries are from that city