Skip to content

Instantly share code, notes, and snippets.

@jkudish
Created September 1, 2011 23:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkudish/1187600 to your computer and use it in GitHub Desktop.
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
<?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 <info@jkudish.com>
* @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;
}
@sae13
Copy link

sae13 commented Oct 25, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment