Hello,
I'm trying to limit the size of the featured image in my form.
I tried to follow the documentation (https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate) and made this code but it dosen't seem to work... I can still upload larger image.
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
print_r($fields);
//validate if specific form
if ($form_data['id']==21)
{
//check if featured image exists
if (empty($fields['_featured_image']['value']))
{
//set error message for featured image
$errors['_featured_image'] = 'Une image est obiligatoire';
}
if (empty($fields['post_content']['value']))
{
//set error message for featured image
$errors['post_content'] = 'La description est obligatoire';
}
//check if featured image exists
if ($fields['_featured_image']['field_data']['size'] >=20000)
{
//set error message for featured image
$errors['_featured_image'] = "L'image que vous avez téléchargé dépasse 200Ko";
}
}
//return result
return array($fields,$errors);
}
Do you have an idea how i can resolve this ?
Thank you
Hi Quentin,
Thank you for getting in touch. I do believe that this isn't the correct pointer for the file size.
Please use this below.
$fields['_featured_image']['file_data']['size']
I noticed that you were using "field_data" instead of "file_data".
Thanks,
Shane
My issue is resolved now. Thank you!