skip to Main Content

WordPress Code Snippets


Limiting Submissions by IP Address in Gravity Forms

You can implement additional security measures, such as limiting the number of form submissions from a single IP address. This helps prevent spam and abuse.

add_action('gform_after_submission', 'codebykp_limit_submissions_by_ip', 10, 2);

function codebykp_limit_submissions_by_ip($entry, $form) {
    $ip_address = $_SERVER['REMOTE_ADDR'];
    $submissions = GFAPI::get_entries($form['id'], array('field_filters' => array(array('key' => 'ip_address', 'value' => $ip_address))));
    
    if (count($submissions) >= 5) { // Limit to 5 submissions
        wp_die('You have reached the maximum number of submissions from this IP address.');
    }
    
    // Save the IP address in the entry meta
    GFAPI::update_entry_property($entry['id'], 'ip_address', $ip_address);
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search