Is there any way to set a limit on the number of times a user can submit a Toolset Form that will allow an unlimited number of submissions per form, but only one submission per form per relationship?
We have the following structure to what we're setting up.
We have a Toolset post form called Slice Freelancer Application that creates a Freelancer post. On our Freelancer post template, we have a second post form called Board Vote that has a conditional display so that only users with a Board Member role or an Admin role can see the Board Vote form. This form creates a Board Vote post. There is a one-to-many relationship established between the Freelancer content type and Board Vote content type. Everything is now working as needed with both these forms thanks to all your previous assistance. For each Slice Freelancer Application submission, we will be having Board Member users casting their votes through the Board Vote form and I've also set up a view to display the board votes conditionally under the form as they come in.
What we would like to do with this now is to limit the Board Vote form to one submission per Board Member user on each page that gets created by the Slice Freelancer Application form. If a Board Member tries to submit a second vote, the system should block them with a message saying "Sorry, but you have already submitted a vote on this Freelancer."
I'm not seeing anything in the Post form setup to cap the number of submissions allowed in any way. I don't want to limit it to one submission per user because then each Board Member will only get to vote on the first applicant they receive via notification. We need the limit to be one submission per Freelancer page with the Board Vote form, drawing on the relationship between that Freelancer page and the Board Vote content type. I don't know if this limit is even possible.
Understood fully if this is something that we need to submit as a job in your Toolset Contractors section. Just let us know if that's the case. As we go through all the steps we'd like to achieve with this Freelancer Application form / Board Voting system, we fully expect to have to post it as a job at some point. But each step we can achieve here is one less step we'll need through the Job Board. And each of the things we ask about may be helpful to future Toolset users seeing this as a ticket. So I'll ask about each desired feature here first. We are trying to emulate a system that we had custom built on the live Drupal version of this site.
Note that I have found the following support ticket that was handled by Luo Yang previously that looks like it may be exactly what I need.
https://toolset.com/forums/topic/limit-the-number-of-cred-form-submissions/
I'd like to ask first if you think the final version of the code will accomplish what I've asked about above. If you think this is what I need, can you let me know which bits of code from this need to be altered to fit my needs. Here's how I'm seeing it:
1) I know I'll need to change the form ID# in line 12 - if ($form_data['id']==1695) to the form ID# corresponding to our Board Vote form.
2) I'm not sure of this one, but I think I'll need to change lines 15-19 from
$shop_id = $_POST['_wpcf_belongs_shop_id'];
$args = array(
'meta_key' => '_wpcf_belongs_shop_id',
'meta_value' => $shop_id,
'post_type' => 'review',
to
$freelancer_id = $_POST['_wpcf_belongs_freelancer_id'];
$args = array(
'meta_key' => '_wpcf_belongs_freelancer_id',
'meta_value' => $freelancer_id,
'post_type' => 'board-vote',
3) I'm not sure of this one, but I think I'll need to change line 30 from
if ( in_array($user_role[0], array('subscriber', 'author', 'contributor', 'editor')) && $user_post_count > 0)
to
if ( in_array($user_role[0], array('board-member', 'author', 'contributor', 'editor')) && $user_post_count > 0)
On this one, I don't think we need anything with author, contributor or editor roles, so please let me know if I can safely remove those from this line. We're only checking users with the Board Member role.
4) I know I'll need to change line 33 from
$errors['wpcf-user-validation']='<span><i class="fa fa-star" aria-hidden="true"> You have already left a Review!</span>';
to
$errors['wpcf-user-validation']='<span><i class="fa fa-star" aria-hidden="true"> You have already cast your vote for this applicant.</span>';
I'm hoping what I've found here is the solution I need to make this one easy. Let me know if you see anything wrong with how I'm interpreting this code, if it will meet my needs, which lines I'll need to change, etc.