Hi @ilan76,
Could you please try this snippet and see how it goes?
<?php
add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) {
// Add your form IDs here.
$form_ids = array( 6 );
// Change this to the message that you want to show.
$message = 'You cannot submit more than 10 times within a day.';
if ( in_array( intval( $form_id ), $form_ids, true ) ) {
$last_entry = wpmudev_get_last_few_entries( $form_id );
if ( $last_entry ) {
$submit_errors[]['submit'] = $message;
$GLOBALS['form_error'] = true;
} else {
$GLOBALS['form_error'] = false;
}
}
return $submit_errors;
},15,3);
function wpmudev_get_last_few_entries( $form_id ){
global $wpdb;
$entry_table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY );
$start_date = date( 'Y-m-d' ) . ' 00:00:00';
$end_date = date( 'Y-m-d' ) . ' 23:59:59';
$sql = "SELECT count(*) FROM {$entry_table_name} WHERE
form_id
= %d AND date_created
>= '%s' AND date_created
<= '%s'";
$entry_count = $wpdb->get_var( $wpdb->prepare( $sql, $form_id, $start_date, $end_date ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( $entry_count >= 10 ) {
return true;
}
return false;
}
add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error_response_submit', 10, 2 );
function wpmudev_invalid_form_error_response_submit( $invalid_form_message, $form_id ){
if ( $form_id != 6 ) {
return $invalid_form_message;
}
if ( $GLOBALS['form_error'] ) {
$invalid_form_message = __( 'You cannot submit more than 10 times within a day.', 'forminator' );
}
return $invalid_form_message;
}
You’ll have to change the line in the above code where you notice 6 to your Form ID.
You can apply the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Please do let us know how that goes.
Kind Regards,
Nithin