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
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.