add_filter('cred_form_validate','func_validate_featured_image',10,2);
function func_validate_featured_image($error_fields, $form_data) {
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
if ($form_data['id']==9999) {
if (empty($fields['_featured_image']['value'])){
//set error message for featured image
$errors['_featured_image'] = 'Missing featured image';
}
}
//return result
return array($fields,$errors);
}
I have a front-end form for inserting a post in my custom post type created with Toolset.
I want to force the user to put the "featured image" and also the gallery photos.
With the code you gave me, this error occurs in the gallery field when I try to submit the form (see attachment).
The problem in the gallery is that I duplicate the images and it presents me with the following errors that are in the attachment.
Could you help me make the "featured image" mandatory?
Thanks so much
Can you please share problem URL where I can see the issue as well as admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Can you please tell me what is the issue with gallery image. Do you also want to validate the gallery image as well? Do you want to make required Gallery images field?
The gallery works fine as it is now set up on the site and the gallery field control works as well.
The problem was that, by entering the code you gave me, the check on the "featured image" went however the gallery fields got bugged and this error came out even if I hadn't put any image in the gallery field (see attachment for the error).
What I would need is to make the "featured image" field mandatory and that everything else in the form works correctly
The gallery works fine as it is now set up on the site and the gallery field control works as well.
The problem was that, by entering the code you gave me, the check on the "featured image" went however the gallery fields got bugged and this error came out even if I hadn't put any image in the gallery field (see attachment for the error) .
What I would need is to make the "featured image" field mandatory and that everything else in the form works correctly .
I've activated the setting "Use the WordPress Media Library manager for image, video, audio, or file fields". So that it will allow you to upload the images using Media library.
Sorry, maybe I explained myself badly.
I don't need the "Use the WordPress Media Library manager for image, video, audio, or file fields" feature because users don't need to see the "WordPress Media Library" images.
What I would like is that that form necessarily requires the "featured image" to submit the form.
I sent the form and in this field the message "This field is required" did not come out because this field "featured image" is not set as mandatory and I would like the "featured image" field to be mandatory (but with the same method of upload that was there before)