• Resolved youdsan

    (@youdsan)


    another problem is … when the limit submission is set to be 1, but 2 computers fill the form the same time, even the first person already click submit, but another person still be able to submit the form. (then it not really only 1), is it possible to block the second person to submit it successfully.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @youdsan

    Hope you are doing fine

    To limit the user submission, you can use the following code snippet. It restricts the submissions to 1 per IP address, for the next 24 hours. In case you need a longer time, change the line where the “$future_time” is defined (+1 is one day), also change the 361 to the id of your form.

    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;
    }

    You can add the above snippet as a mu-plugin on your site:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Hope this information is helpful.

    Kind regards

    Luis

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @youdsan ,
    ?
    We haven’t heard from you for several days now, so it looks like you no longer need our assistance.
    ?
    Feel free to re-open this ticket if needed.
    ?
    Kind regards
    Kasia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘limit submission = 1 but 2 persons still be able to submit the form’ is closed to new replies.