Skip Navigation

[Resolved] Limiting number of images on CRED

This support ticket is created 2 years, 8 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by SteBlood 2 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2351593

Hello, I have tried to follow the following;

https://toolset.com/forums/topic/putting-a-limit-on-images-field/

The code 'works' in a fashion, but it doesn't allow me to upload 'any' images.
It will spit out the error regardless of how many images I am uploading or not.

Here is an example of the code on my site;

add_filter('cred_form_validate','imagecheck',10,2);
function imagecheck($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==389 || $form_data['id']==238045)
{
//check my_field value
if (count($fields['wpcf-additional-images']) > 10)
{
//set error message for ls-photos
$errors['wpcf-additional-images']='Only a maximum of 10 images can be uploaded';
}

}
//return result
return array($fields,$errors);
}

Many Thanks

Steve

#2351661

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Looking at the code, it looks ok to me but need to check whats going wrong with your setup.

Can you please share problem URL and admin access details and tell me how many images you want to allow users to be uploaded.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2351805

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the custom code you added as given under:

add_filter('cred_form_validate','imagecheck',10,2);
function imagecheck($error_fields, $form_data) {
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values

  
//validate if specific form
if ($form_data['id']==1212 || $form_data['id']==238045){
//check my_field value
     if (count($fields['wpcf-additional-images']['value']) > 2) {
      //set error message for ls-photos
      $errors['wpcf-additional-images']='Only a maximum of 2 images can be uploaded';
      }
}
//return result
return array($fields,$errors);
}

Where the line adjusted is as follows:

   if (count($fields['wpcf-additional-images']['value']) > 2) {

Can you please confirm it works as expected now.

#2351863

Minesh is the man! Yeaaa!

Nice one mate. My issue is now resolved!