Skip Navigation

[Resolved] Toolset Form – Limit size featured image

This support ticket is created 3 years, 10 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by quentinR 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#2325115

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

#2325151

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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

#2328807

My issue is resolved now. Thank you!