add_filter('frm_validate_entry', 'check_submitted', 20, 2);
function check_submitted($errors, $values){
if ( $values['form_id'] !== 6 ) {//Change 30 to the ID of your form
return $errors;
}
$entries_submitted = FrmProStatisticsController::stats_shortcode( array( 'id' => 182, 'type' => 'count', 'user_id' => 'current', 'created_at_greater_than' => 'this month' ) );//change the params to the params of your stat
if ( $entries_submitted >= 1 ){//change 1 to your limit number
$errors['too_many'] = 'You filled this form this month, please register the feedback in the next month.';//Change this to your error message
}
return $errors;
}
`
Let us look at 'created_at_greater_than' => 'this month' part of the code you shared. Does that make any sense? I think the first part is botching your request. To limit to the current month you should not be trying to count entries that are ultimately created at "greater_than" this month, correct?
According to the stats_shortcode parameters seen here: https://formidableforms.com/knowledgebase/add-field-totals-and-statistics/ we only have "created_at_greater_than" and "created_at_less_than" to work with. Let's see if incorporating that logical language into the code solves the problem.
'created_at_greater_than' => 'first day of this month', 'created_at_less_than' => 'last day of this month'
Here we are counting only the entries that have a created date of "greater than" the first day of this month and then also a created date of "less than" the last day of this month.
Logically that should count all entries within the current month and return the value you are expecting.
Awesome. Yeah, all code needs thorough testing.
Please login or Register to submit your answer