Tell us what you are trying to do? validate file extension during upload and restrict acceptable file type to csv, xls, and xlsx
Is there any documentation that you are following?
https://toolset.com/errata/a-note-on-using-the-cred_form_ajax_upload_validate-hook/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_ajax_upload_validate
Is there a similar example that we can see?
What is the link to your site?
lien caché
I wrote the following function but the files i can upload to the custom field can be any type.
add_filter('cred_form_ajax_upload_validate', 'y2risk_validate_portfolio_file_format', 10, 2 );
function y2risk_validate_portfolio_file_format( $error_fields, $form_data ) {
// Get the list of uploading fields and errors
list( $fields, $errors ) = $error_fields;
// if the form is 881 or 386
if ( $form_data['id'] == 881 || $form_data['id'] == 386 ) {
$uploaded_file_format = $fields['wpcf-u-sngl-portfolio-file']['field_data']['type'];
$accepted_file_formats = array(
'text/csv', // csv
'application/vnd.ms-excel', // xls
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' // xlsx
);
if ( ! in_array( $uploaded_file_format, $accepted_file_formats ) ) {
$errors['File-Format-Error'] = 'The file is not an accepted format. Accepted formats: .csv, .xls, .xlsx';
}
}
return array( $fields, $errors );
}
for some reason when I upload a file type other than the one I want the error does not display and the file type is accepted.
Please help,
Thanks,
David
My issue is resolved now. Thank you!