Support

Account

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

  • Hi,

    For those who comes across this and not being able to update/edit posts you can add if(is_numeric($value)) { to the code to check if the field is already stored like so:

    At least that seems to work for me.

    add_filter('acf/validate_value/type=file', 'my_acf_validate_value_file', 10, 4);
    
    function my_acf_validate_value_file( $valid, $value, $field, $input ){
    
    	if(is_numeric($value)) {
    		return true;
    	} else {
    	
    		// 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;
    	}
    		
    } 

    Kind regards
    Henrik