Support

Account

Home Forums Front-end Issues Frontend form file upload validation Reply To: Frontend form file upload validation

  • Hi @gregor

    I can reproduce it now. It seems that the basic uploader doesn’t check the file type. As a workaround, you can try the following code:

    add_filter('acf/validate_value/type=file', 'my_acf_validate_value', 10, 4);
    
    function my_acf_validate_value( $valid, $value, $field, $input ){
    	
    	// bail early if value is already invalid
    	if( !$valid ) {
    		
    		return $valid;
    		
    	}
        
        // Get the allowed types and store it in an array
        $allowed_types = explode(',', trim($field['mime_types']));
        
        // Get the current file extension
        $file_extension = pathinfo($value)['extension'];
        
        // Check if the current file extension is allowed or not
        if( !in_array($file_extension, $allowed_types) ){
            $valid = 'This file type is not allowed';
        }
    
    	// return
    	return $valid;
    		
    }

    If you want, you can also open a new ticket so this issue can be passed directly to the plugin author? You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket.

    I hope this helps 🙂