Saltar navegación

[Resuelto] Set a limit in a repeatable group field form

This support ticket is created hace 3 años, 9 meses. 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: Africa/Casablanca (GMT+01:00)

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por HorusA5173 hace 3 años, 9 meses.

Asistido por: Jamal.

Autor
Mensajes
#2024039

Tell us what you are trying to do?
Im trying to create a form for a repeatable field group but i need to limit the number of times that you can submit that for to 3, so you can only have 3 groups created
heres an example: i have a custom post called Studio each studio can only have 3 trainers (i set a repeatable group for trainer data inside studio) how can i limit to 3 trainers for each studio?

#2024159

Hello and thank you for contacting the Toolset support.

Currently, the option to limit the number of items in an RFG is not supported. It will need custom code to be implemented.

You can implement a Javascript code to hide the button or disable the field when 3 items are added. And add a PHP code to validate the form and only allow 3 items in the RFG. Custom code in this previous thread may inspire you https://toolset.com/forums/topic/require-limit-number-of-repeating-field-group-entries/

I hope this helps. Let me know if you have any questions. Please provide a URL where we can see the form and screenshots when relevant.

#2024447

I finally found out how to do it, I think there is a lack of support from you since I had to search through several threads to find the answers and they are never concrete answers
i use this code in the fucntions file

function train_count() {
    $train_count = count( get_posts( array( 
    'post_type' => 'trainers', 
    'author'    => get_current_user_id(), 
) ) );
         
    return $train_count;
}

then i register this function in toolset settings and use a conditional block to hide the form when $train_count = 3
thats it, im posting this solution in case anyone need it in the future.

#2024453

My issue is resolved now. Thank you!
I finally found out how to do it, I think there is a lack of support from you since I had to search through several threads to find the answers and they are never concrete answers
i use this code in the fucntions file

function train_count() {
    $train_count = count( get_posts( array( 
    'post_type' => 'trainers', 
    'author'    => get_current_user_id(), 
) ) );
         
    return $train_count;
}

then i register this function in toolset settings and use a conditional block to hide the form when $train_count = 3
thats it, im posting this solution in case anyone need it in the future.