Hi, I' ve read this post here https://toolset.com/forums/topic/types-file-custom-field-and-cred/ which sounds idea, however I have 4 different cred form IDs I'd like to use it with - I'm a newbie when it comes to PHP/jQuery etc - so not sure how I would change the example to work with 4 ID's rather than just the one.
Any help would be greatly appreciated.
There is another way to target a CRED form by id, with a different hook name. Lets say you have forms 20, 21, 22 & 23.
add_filter('cred_form_validate_20','cred_filetype_size_validation',10,2);
add_filter('cred_form_validate_21','cred_filetype_size_validation',10,2);
add_filter('cred_form_validate_22','cred_filetype_size_validation',10,2);
add_filter('cred_form_validate_23','cred_filetype_size_validation',10,2);
function cred_filetype_size_validation($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;
//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
if (isset($_FILES['wpcf-the-file-field']['type'])) && (isset($_FILES['wpcf-the-file-field']['size'])) {
//Retrieve file type
$file_type_uploaded=$_FILES['wpcf-the-file-field']['type'];
//Retrieve file size
$file_size_uploaded=$_FILES['wpcf-the-file-field']['size'];
//Validate files uploaded, make sure its PDF file type AND not more than 100kB
if (!( ('application/pdf' == $file_type_uploaded) && ($file_size_uploaded < 100000) )) {
//Validation failed,
// set error message per field
//Remove wpcf - prefix here!
$errors['the-file-field']='Sorry the file you have uploaded is not of correct type or exceeded 100kB limit.';
}
}
//return result
return array($fields,$errors);
}
Please let me know if you are satisfied with my reply and any other questions you may have.
Regards,
Caridad
Thanks Caridad, I had to put extra brackets around line 12, but that seems to work well.
I have another couple of questions regarding Cred and Types, but will add them to new posts so people can search them for future reference (I know I've found articles on this forum really helpful).
Thanks
Adam
Dear Caridad,
For the script $_FILES['wpcf-the-file-field']['type'], what is the 'wpfc-the-file-field' if my field tag is "brcopy"?
Best regards,
Kelvin.