Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @atlasinternational

    I hope you are doing good today.

    I pinged our Forminator Team to review your query and this snippet as it could be outdated already. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi again @atlasinternational

    Could you try this code as a mu-plugin?

    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) {
    	// Add your form IDs here.
    	$form_ids = array( 361 );	 
    	// 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);
    
    add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error', 10, 2 );
    function wpmudev_invalid_form_error( $invalid_form_message, $form_id ){
    	if( $form_id != 361 ) {
    		return $invalid_form_message;
    	}
    	$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 ) {
    				$invalid_form_message = __( 'You cannot submit more than 1 time within 24 hours.', 'forminator' );
    			}
    		}
    	}
    	return $invalid_form_message;
    }

    Please change the form ID from 361 to your form ID.

    You can learn here how to add mu-plugin into your site:

    Must Use Plugins

    Kind Regards,
    Kris

    Plugin Support Kasia – WPMU DEV Support

    (@wpmudev-support2)

    Hello @atlasinternational ,

    We haven’t heard from you for a while now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Prevent Resubmission’ is closed to new replies.