Thanks Victor, hmmm.....yes, that does seem overly complicated.
Maybe I should just rethink what I want the form to do and not go overboard.
Instead of having separate limits for the two different user roles, which seems to be the major issue here, can I instead put a limit of say 100 entries per user no matter the user role?
You could, but you still have to count previous entries to make sure they are <=100. It doesn't matter what number you choose, the process is the same. Another possibility is to create a custom user meta field to store the entry count, but that means you have to update the field with the new count every time an entry is saved.
It wouldn't take very long for a developer to do this for you. If you need help, please search our Developers Directory at <a href="https://formidable-masterminds.com/developers-directory/" rel="nofollow">https://formidable-masterminds.com/developers-directory/</a>.
It'd be nice to have a Formidable extension that expanded the Form Limits in Form Settings with conditional logic based on user role and user meta:
"Limit number of entries based on User Role.." and "If value in User Meta "custom_meta_selector_here" is =< "50", then close form and display message..
🙂
I suppose if we were to design something like this, user role would probably have to be some kind of multi-select that wouldn't be subject to a single role/count.
There would have to be a way to assure every entry created updates the count.
What about entry deletions? Does the count decline?
It might be helpful to have a count reset if the count somehow gets off.
Any other ideas about how this could work?
I decided to come back to this issue because after 1 year hiatus because I needed this to work for me on another website. I FINALLY got it to work based on the user roles. I took code from here and there and added my own code, it may not be pretty but it works and would be great if others add to it to make it even better. I just about know enough where I am dangerous. To refresh the issue I had, I have 2 user roles on the website, one for the public and one for businesses when they register. I have a form that allows the public to submit a form only 1 time and for businesses they can submit the same form for up to 25 times (You can change this number as well as adding more functions if you have more user roles). This is the code I came up with, All you need to do is change the count to each user roll that you want to set it to.
add_action('frm_display_form_action','check_entry_count','my_get_current_user_roles', 10,3 );
if($form->id == 49 and !is_admin()){ //replace 49 with the ID of your form$user = new WP_User( $user_ID );
function check_entry_count($params, $fields, $form){
global $user_ID;
remove_filter('frm_continue_to_new', '__return_false', 50);
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
foreach ( $user->roles as $role );}
if ($role == public) {
echo 'You are registered as a private seller. You can list 1 item.';
}
elseif ($role == business) {
echo 'You are registered as a business, you can list up to 25 items.';
}
$count = FrmEntry::getRecordCount("form_id=". $form->id ." AND user_id=".$user_ID);if($count >= 1 && $role == 'public'){ //change 1 to your entry limit
echo 'This form is closed - you have reached your 1 item limit';
add_filter('frm_continue_to_new', '__return_false', 50);
}if ($count >= 25 && $role == business) { //change 25 to your entry limit
echo 'This form is closed. - You have reached your 25 item limit.';add_filter('frm_continue_to_new', '__return_false', 50);
}
}
}
Please login or Register to submit your answer
Just an update I was given this code by FF subport to "Limit the number of entries per user".
I missed this code while searching for an answer.
I think this would do, at least for me. Hope it can help others as well.
add_action('frm_display_form_action', 'check_entry_count', 8, 3);
function check_entry_count($params, $fields, $form){
global $user_ID;
remove_filter('frm_continue_to_new', '__return_false', 50);
if($form->id == 5 and !is_admin()){ //replace 5 with the ID of your form
$count = FrmEntry::getRecordCount("form_id=". $form->id ." AND user_id=".$user_ID);
if($count >= 2){ //change 2 to your entry limit
echo 'This form is closed';
add_filter('frm_continue_to_new', '__return_false', 50);
}
}
}
This code does nothing about user roles. It bases the count off of the WordPress user id. You still have to add code to test if the users are business or public.
Yes, you are correct, but at least with this code I can put a cap on the same number of form submissions across the board even though it's the same for both public and business. It takes away their ability to be able to submit unlimited submissions.
I really do wish and prefer that I was able to separate the number of submissions based on the user role instead.
This is now a work in progress for the foreseeable future for me.
If worse comes to worse, I might just hire a developer.
You can get the code from this snippet to get the user role: https://formidable-masterminds.com/conditionally-require-fields-by-user-role/
Here's the code Formidable gave modified for the business and public user roles. https://gist.github.com/vfontjr/5d072ab98c24568ca3a1ab9a690ef3ed
<p>Thanks Victor and Joe for mentioned this ones, could we make the count entries in a specifc range of date or current day? then it could do limit number of submission by user role per day or in a period</p>