Tell us what you are trying to do?
Trying to force PDF only on repeatable file upload for Ajax form. I found some code from Toolset docs but its not working. It is fairly old so it might be out dated now?
function my_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;
//validate if specific form
if ($form_data['id']==135)
{
//check if uploaded file is right type
if ($fields['wp-cf-wills-and-expression-of-wish-forms']['field_data']['type'] != 'application/pdf')
{
//set error message for file
$errors['wills-and-expression-of-wish-forms'] = 'Wrong file type';
}
}
//return result
return array($fields,$errors);
}
add_filter('cred_form_ajax_upload_validate','my_validation',10,2);
My issue is resolved now. The following code forces pdf only and limits upload size.
//Limit upload file size for repeating image custom field
add_filter('cred_form_validate','story_image_size_validation',10,2);
function story_image_size_validation($field_data, $form_data)
{
list($fields,$errors)=$field_data;
$arr = array(135);
if (in_array($form_data[id], $arr)){
if(isset($fields['wpcf-wills-and-expression-of-wish-forms']['file_data']['size']['type'])){
if($fields['wpcf-wills-and-expression-of-wish-forms']['file_data']['size']>10000){
$errors['wills-and-expression-of-wish-forms']='the image size should not be more than 10000 bytes';
}
if ($fields['wpcf-wills-and-expression-of-wish-forms']['file_data']['type'] != 'application/pdf'){
$errors['wills-and-expression-of-wish-forms']='only pdf format allowed';
}
}
}
return array($fields,$errors);