Skip Navigation

[Resolved] cred_form_ajax_upload_validate – validate file extension

This support ticket is created 2 years, 11 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.

This topic contains 1 reply, has 1 voice.

Last updated by davidZ-4 2 years, 11 months ago.


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?

Is there a similar example that we can see?

What is the link to your site?
hidden link

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/', // 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,



My issue is resolved now. Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.