In order to best help with this one I would need to know if this is for the backend or is it for a Frontend form?
The reason is because there isn't a validation function for the fields on the backend and there isn't any provision in our UI to make this field required.
However on the frontend form we can use a validation hook to check to ensure that the checkbox isn't submitted empty.
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($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
//print_r($fields);
//validate if specific form
if ($form_data['id']==710)
{
//check if featured image exists
if (empty($fields['type-klant']['value']))
{
//set error message for featured image
$errors['type-klant'] = 'No value selected';
}
}
//return result
return array($fields,$errors);
}
Can you try this and let me know if it helps. You can add it to your theme's functions.php file or our Toolset custom code section and activate it.
I tried to add the above code over Toolset's custom code feature in settings but unfortunately the snippet cannot be edited directly. I get a warning to check file permissions and wp-config.php constants DISALLOW_FILE_EDIT and DISALLOW_FILE_MODS. Ot ot alternatively edit the file manually.
You added the code in expert mode.
By switching back to the visual editor all the edits to the form are lost.
Moreover only the first checkbox is required to fill out now, though we want to choose which checkboxes should be mandatory.
This is not what we asked for.
We asked for a simple fix to make checkboxes of our choice mandatory or not in the visual editor.
Reset the form as it was before and get the fix done.
The only way to make the fields required is through the validation hook.
With your form the main issue is that we are unable to set all of them as required because most of them are hidden in conditionals. SO the hook will check all the fields to see if they are selected.
Unless all the fields have a value selected then the form won't submit. So the solution to this is to make only the dependent checkbox required, which is used to trigger the other checkbox fields.
The form is displaying as intended on the frontend. However i'm seeing where the generic fields are missing.
Are you able to recreate the conditionals in the visual builder?
When you go to the page below please let me know what you are seeing. hidden link
Also if you have a backup of the site you can restore this if the form elements are missing. Also you mention this "You added the code in expert mode."
I didn't add any code in expert mode. The code I added was added to Toolset->Settings->Custom Code.
The form was switched to expert mode to see what the field names were in order to setup the custom validation.