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