[Forminator Pro] Limit form entries by IP Address & Time

Hi, in Forminator Pro, is there a way to limit form entries to once every 24 hours per IP address?

  • Kris
    • Support

    Hi Tom

    Hope you are doing good today.

    Current settings does not allow for such behave. I ping our SLS Team (code experts) so that they check if this will be possible. We will post an update here as soon as more information is available.

    Please keep in mind that our SLS Team deals with more complicated issues, so it may take a little longer for them to reply here. Thank you for your patience while we look into this further.

    Kind Regards,
    Kris

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey Tom ,

    I've made a mu-plugin for you that limits the form submissions for 24hours if they are from the same IP and for the same Form.

    How to install:
    Always make sure to keep a backup of your site before changing/adding custom code.

    1] Navigate to your /wp-content/ directory and create a new one named mu-plugins if it doesn't exist.
    2] Inside the mu-plugins folder create a file named frmt-limit-form-sub.php
    3] Edit the file and copy / paste this code snippet inside.

    <?php
    
    add_filter(
    	'forminator_custom_form_submit_errors',
    	function( $submit_errors, $form_id, $field_data_array ) {
    		// Add your form IDs here.
    		$form_ids = array( 49, 15, 20 );
    
    		// Change this to the message that you want to show.
    		$message = 'You cannot submit more than 1 time within 24 hours.';
    
    		if ( in_array( intval( $form_id ), $form_ids, true ) ) {
    
    			$user_ip = Forminator_Geo::get_user_ip();
    
    			if ( ! empty( $user_ip ) ) {
    				$last_entry = Forminator_Form_Entry_Model::get_last_entry_by_ip_and_form( $form_id, $user_ip );
    
    				if ( ! empty( $last_entry ) ) {
    					$entry        = Forminator_API::get_entry( $form_id, $last_entry );
    					$current_time = strtotime( date( 'Y-m-d H:i:s' ) );
    					$future_time  = strtotime( '+1 day', strtotime( $entry->date_created_sql ) );
    
    					if ( $current_time < $future_time ) {
    						$submit_errors[]['submit'] = $message;
    					}
    				}
    			}
    
    		}
    
    		return $submit_errors;
    	},
    	15,
    	3
    );

    4] Save and close the file.
    5] The final path should look like /wp-content/mu-plugins/frmt-limit-form-sub.php

    You should edit the "$form_ids = array( 49, 15, 20 );" adding the ID of the Form that you want this check to work with ( you can add multiple forms as you can see as a comma separated list ). And you can also change the $message to show anything you like for a form error.

    As an example this is my form with the error shown.

    Tell me if you need any further help with this!

    Regards,
    Konstantinos

    • Tom
      • Site Builder, Child of Zeus

      WOW!! Thank you very much. I'll have to save this for a time I can use it personally.

      Unfortunately, I really need this to be more of a FLAG when building the form. Reason being, I can not give my client access to the code to update the Forms ID Array.

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey Tom ,

    Could you explain a bit more what do you mean by a "flag when building the form" ?

    Also if you want it for all forms then we can simply remove the array check so it will work for all forms as well if that's easier for example.

    I'm trying to understand just in case I could help you a little bit more in case it can be used for your client.

    Regards,
    Konstantinos

    • Tom
      • Site Builder, Child of Zeus

      On every form, there is a Settings section. Currently there is a setting called "Data Storage" which allows you to toggle (flag, switch, etc) on/off to "Disable store submissions in my database.

      Adding such a toggle to prevent duplicate entries would be AWESOME :slight_smile: If you could specify a period of time in hours would be even better.

      Hope this makes sense.

  • Nithin
    • Support Wizard

    Hi Tom,

    On checking further, I'm afraid, there isn't an easy workaround to make such changes in the plugin side out of the box. We have already forwarded this as a feature request to our developer so that our Forminator team could check the possibilities of such feature, and see whether this is something that could be implemented this down the roadmap.

    At the moment, I'm afraid, using the mu-plugins as mentioned would by Konstantinos would be the easiest workaround to achieve the workflow.

    Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.