Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Can you please tell me where you added the code you shared above?
I have added that code into function.php file
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Can you please check now.
I've adjusted the code added to your theme's functions.php file as given under:
add_filter('cred_form_validate','func_validate_image_repeating_field_size',10,2);
function func_validate_image_repeating_field_size($error_fields, $form_data) {
list($fields,$errors)=$error_fields;
// target form IDs
$forms = array( 1867 );
if (in_array($form_data['id'], $forms ) ) {
/// target form field
$form_fields = array("wpcf-crew-member-images");
/// allowed size - change as required
$number_of_mb_limit = 2;
$max_size = $number_of_mb_limit * 1024 *1024;
/// allowed number of images - change it as required
$allowed_count = 2;
foreach($form_fields as $k=>$v):
$count = count($_FILES[$v]['type']);
for($i=0;$i<$count;$i++) {
$size = $_FILES[$v]['size'][$i];
if ( ( $size >= $max_size and $count > $allowed_count) ) {
$errors[$v] = "Sorry the file you have uploaded exceeded 2MB limit and upload maximum $allowed_count files.";
break;
}else if($size >= $max_size){
$errors[$v] = 'Sorry the file you have uploaded exceeded 2MB limit.';
break;
}else if($count > $allowed_count){
$errors[$v] = "You are allowed to upload maximum $allowed_count files.";
break;
}
}
endforeach;
}
return array($fields,$errors);
}
I also suggest with your form:
- hidden link
Under the repeating image field you should add a note that gives information to users that what size is allowed for user and how many files a user can be allowed to upload.