Support

Account

Home Forums Front-end Issues Custom Validation Reply To: Custom Validation

  • Im using acf/validate_valuepassing wp_check_filetype to make sure images uploaded via a front end form are image types, the code below is working perfectly on the front end, however when I go to publish the post created by the form in the backend (as its automatically saved as a draft) I get the error message for when it is not a accpeted file type , when it is.

    My question is how do you use acf/validate_value to check that the file uploaded is an image type, I am using the Basic file uploader so guests can upload images

    //FORM IMAGE VALIDATION
    add_filter('acf/validate_value/name=image_upload', '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;	
    	}
    	$filetype = wp_check_filetype($value);
    	$filetypeext = $filetype['type'];
    	if( $filetypeext != 'image/jpeg' && $filetypeext != 'image/gif' && $filetypeext != 'image/png' && $filetypeext != 'image/bmp'&& $filetypeext != 'image/tiff' && $filetypeext != 'image/jpg') {
    		$valid = "Please upload a valid image file!";
    	}
    	// return
    	return $valid;
    }