Skip Navigation

[Resolved] Limiting number of times someone can submit a Toolset form per relationship.

This support ticket is created 2 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by melodyM 2 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2511187

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.

#2511553

Hello,

The thread you mentioned above is outdated.

You can try these:
In the single "Freelancer" post, display a post view:
- Query child "Board Vote" posts
- Filter by:
a) post type relationship between "Freelancer" and "Board Vote"
b) post author is same as current logged-in user
https://toolset.com/course-lesson/allow-users-to-manage-their-items/#create-a-view-that-lists-the-item-of-the-currently-logged-in-user
- display only one item
- In view's loop, if does not found any item, display the child post form for creating new "Board Vote"

#2511637

Let me make sure I'm understanding your logic on this one first. Are you saying that I should set up a conditional display on the page that will check for posts authored by the same user account as the person viewing the page and then show either the Board Member user's Board Vote if they have already voted or the Board Vote form if they haven't voted?

If so, that's some really good logic there. I'll try that and I'll let you know if I have any difficulty. We just need to make 100% sure each Board Member can only vote once. The reason for this isn't because we're so worried that the board members will vote twice though. It's part of a larger logic process for what we're wanting with this where we're hoping to get an action triggered when all board members have completed their single vote. Having them limited to one vote each means the total number of votes can't be reached by any means other than each Board Member voting once. That's the first step of what we're trying achieve here. I have another ticket open for the second step and there will be another step after that which will likely require Toolset Job Board level coding help. I'll reply further on this in a few hours after I try to set this up as you've indicated. Thanks as always.

#2511719

This worked perfectly. It took me a bit to perfect how I wanted everything to display, but I believe I have it working to restrict the form submission to one per Board Member user. One step closer to having everything on this. Nearly all the way there now.

My issue is resolved now. Thank you!