Is it possible to limit the total number of files a user can upload? I've implemented code which is working to hide the "Add more" button but I'm wondering about limiting the number of files a user can upload through the WordPress uploader. Is that possible or do you have any suggestions on how to achieve that?

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
As I understand you are using media uploader to upload the images and you want to limit the number of files to be uploaded in backend or using Toolset forms?
Yes, that is correct. The issue I'm having is that a user can upload unlimited images since the WordPress media manager allows for multiple uploads at one time – even if I limit the number of repeater fields they can add via the jQuery I've added.

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
As you are using the Media uploader there is no easy way to check.
Can you please try to check the following code and see if that helps:
- versteckter Link
OR
You can use the server side validation hook - cred_form_validate, please check if that helps:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
If you want to use the repeating field to upload image - then you can restrict it using JS, here is reference ticket.
- https://toolset.com/forums/topic/limit-number-uploading-files/#post-335393
I tried the code you suggested here (versteckter Link) but it didn't seem to work. Any help refining that code might help.
I've already implemented the last suggestion you made but the issue is that when the multi-instance option is turned on you can upload as many images as you want even if you can only add six instances of a field.

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
I've already implemented the last suggestion you made but the issue is that when the multi-instance option is turned on you can upload as many images as you want even if you can only add six instances of a field.
==>
Regarding this, what if we hide :Add New button once user reach to 6th instance of the repeating field?
Or you are saying even if we hide the "Add New" button after six instance but using media uploader users are still able to upload multiple images?
Yes, "Or you are saying even if we hide the "Add New" button after six instance but using media uploader users are still able to upload multiple images?" is exactly what is happening. Even though the "Add new" button is limited to 6 the user can upload as many media files as they want through the wordpres media manager.
We are trying to avoid this to keep the number of files smaller instead of letting users just upload as many as they want.

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
Toolset uses the WordPress standard media uploader and I do not think if media uploader offers any limits.
As of now I do not have any workaround or solution to offer you, if you stop using media uploader then I will have a solution for you or you will have to wait a bit and allow me some time to find workaround (if possible) as I need to debug big deep but I do not promise that I will have a solution to offer. I will just give a try when I get some time. Let me know if that is OK for you.
Hey Minesh,
Thank you for your response. That sounds great and I totally understand that it is a WordPress limitation. I appreciate your help.

Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
I tried to devote some time but unfortunately I do not have any workaround to offer at the moment.
When I see its only ask to use the following filter: wp_handle_upload_prefilter
=> https://wordpress.stackexchange.com/questions/21084/how-can-you-limit-the-number-of-images-videos-that-can-be-uploaded-to-a-wordpr
Can you please check the code snippet offered on the above link and check if that helps.
Thanks Minesh! I think I found a plugin (versteckter Link) that might work. I'm going to be doing some testing. I appreciate you looking in to this.