Hello Toolset Support Team,
We are using your Classifieds Reference Site and we are customizing your ad packages. We want to limit the amount of images for the 'Free Package' to 3 images.
If you can help us come up with a solution, we would be very appreciative.
Thank you,
JunkPal Development
Hi, the code in the Classifieds plugin isn't written to be easily extensible, and adding new packages or modifying existing packages is not recommended. We don't recommend modifying the functionality of the Classifieds Reference site, and it is not meant to be used as a boilerplate for creating your own classifieds site. It's meant to show what is possible with Toolset and custom code.
With that being said, in general you can use the Forms API cred_form_validate to validate image uploads when AJAX is not used on the Form. Add this code to your child theme's functions.php file:
add_filter("cred_file_upload_disable_progress_bar", "disable_progress_bar");
function disable_progress_bar($val) {
return true; //return true to disable
}
function not_empty($var) {
return $var != '';
}
add_action('cred_form_validate', 'toolset_repeating_image_count_restriction',10,2);
function toolset_repeating_image_count_restriction($error_fields, $form_data) {
$forms = array( 12345 );
// Field data are field values and errors
list($fields,$errors) = $error_fields;
if (in_array($form_data['id'], $forms ) && isset($_FILES['wpcf-rept-img']['tmp_name']) ) {
$not_empty = array_filter($_FILES['wpcf-rept-img']['tmp_name'], 'not_empty');
if(count($not_empty) > 3) {
$errors['rept-img'] = __("Maximum of 3 images allowed", "your-theme-domain");
}
}
$field_data = array($fields,$errors);
//return result
return $field_data;
}
Change 12345 to match the Form's numeric ID, change rept-img to match the repeating image field slug, and change the error message as needed.