>Tell us what you are trying to do?
Validate files that people attach in post form. Specifically I want to validate file type to enable sending only PDF and only in Custom Field. It's not working or it blocks all files attached in custom field
On top of that I increased custom code snippet priority to 100 as recommended here: https://toolset.com/forums/topic/custom-code-snippet-not-running/
I also put custom code in Toolset >> Settings >> Custom Code, not the other way.
I saved and tested custom code, I also activated these code snippets, one at a time. Seems like it should work, but it's not.
>Is there a similar example that we can see?
I found only those examples from links above
What can I do to make it work and validate only PDF files?
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;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==12)
{
//check my_field value
if ($fields['wpcf-my_field']['file_data']['type']!='pdf')
{
//set error message for my_field
$errors['my_field']='Not a PDF file';
}
}
//return result
return array($fields,$errors);
}
In this code above you will need to change the wpcf-my_field to the slug of your pdf field keeping the wpcf prefix. Also replace the form id 12 with the ID of your form.