Skip Navigation

[Resolved] Limit the number of times a repeatable group shows on a form

This support ticket is created 2 years, 10 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by lesleyA 2 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#2323045
Screen Shot 2022-03-21 at 14.48.09.png
Screen Shot 2022-03-21 at 14.43.34.png

Tell us what you are trying to do?
I am trying to allow a repeatable group to show no more that three times.

Is there any documentation that you are following?
https://toolset.com/course-lesson/conditional-display-for-form-inputs/?utm_source=plugin&utm_campaign=forms&utm_medium=gui&utm_term=See%20our%20documentation%20on%20conditional%20display%20for%20form%20inputs
I have looked at this thread: https://toolset.com/forums/topic/set-a-limit-in-a-repeatable-group-field-form/ as the author seemed to have found a way.

Here's what i have done:
I made a repeatable group for my post type: Experts and suppliers (see pic)
I then used the code from the above post like so:

function package_count() {
$package_count = count( get_posts( array(
'post_type' => 'package-rates',
'author' => get_current_user_id(),
) ) );

return $package_count;
}

I then added a conditional group to my form and there tried to add a condition manually (lol!)
[cred_show_group if="($package_count <= '3')" mode="fade-slide"]

But it doesn't work, because I'm not yet capable of this type of thing! If you can shed some light, I would be very grateful!

Thank you

Is there a similar example that we can see?

What is the link to your site?

#2323111

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lesley,

Thank you for getting in touch.

In this user's case they were using the conditional block and not the forms conditional which doesn't allow for the use of custom functions.

What I believe this user is doing is to check based on the current user, how many posts he has in the repeatable fields and then hide the option when the limit of 3 is reached.

So the entire form is being hidden using a conditional block. Are you displaying this form using Toolset Blocks? If so then you can make use of our Conditional block and use the function name to perform the checks.

However the function will first need to be registered at Toolset -> Settings -> Frontend and under the "Functions inside conditional evaluations" setting.

Thanks,
Shane

#2323123

I see, thank you for elaborating. Is there a way to show a repeatable field a given number of times on one form? I'd like my customers to be able to add the details for up to three packages in the first instance.

#2323155

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lesley,

In general the populating the repeatable field group is done by submitting the form one after the other.

They will need to submit the form 3 times. It won't be possible to submit all 3 request at once given that repeatable field groups are essentially posts in a hidden relationship.

Thanks,
Shane

#2323167

Ah, I see. I've definitely gone about this the wrong way. I need some help unravelling my errors.

At the moment I have my work flow like this:
supplier on-boarding (post form) goes to supplier packages (post form) goes to supplier referees (post form) goes to member (user form).

This crashes the site!!!

Perhaps I need to do things in a different order?

#2323315

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lesley,

Perhaps I can have a look at it through the site to see exactly what was done.

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please where applicable please provide me with a link to an example page where I can see the issue.

I've enabled the private fields for your next response.

Thansk,
Shane

#2323899

My issue is resolved now. Thank you!