Home › Forums › Front-end Issues › Custom Validation › Reply To: Custom Validation
Im using acf/validate_value
passing 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;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.