Skip Navigation

[Resolved] putting a limit on images field

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 2 replies, has 2 voices.

Last updated by jimH-3 2 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2316745

Tell us what you are trying to do?
I would like to limit the number of photos allowed to be uploaded to 10
Is there any documentation that you are following?
I did use a support ticket found for code
Is there a similar example that we can see?

What is the link to your site?
hidden link

You will need to log in to the site to get the form to load. I would also give you admin access so you can look at the Custom code snippet written for Toolset:

<?php
/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

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']==174 || $form_data['id']==238045)
{
//check my_field value
if (count($fields['wpcf-all-listing-photos']) > 4)
{
//set error message for ls-photos
$errors['all-listing-photos']='Only a maximum of 4 images can be uploaded';
}

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

The code runs but the count for the field is always 7 no matter how many images I add or how few.

#2316977

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes, can you please share admin access details.

*** 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.

#2317399

My issue is resolved now. Thank you!