You mean all of the fields added on form you want to set as required field? If yes:
Can you please send me 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.
function my_validation($error_fields, $form_data) {
list($fields, $errors) = $error_fields;
// Log the form ID to verify that this function is being called.
error_log('Form ID: ' . $form_data['id']);
// Only validate for the specific form.
if ($form_data['id'] == 111182) {
if (empty(trim($fields['wpcf-school-district']['value']))) {
$errors['wpcf-school-district'] = 'This field cannot be empty';
error_log('Validation error: Company field is empty');
}
}
I just ended up throwing some javascript validations.
jQuery(document).ready(function(){
jQuery('#cred_form_111182_1_1').on('submit', function(e) {
// Define validation rules for each field.
var validations = [
{ selector: 'input[name="wpcf-school-district"]', message: 'School district is required and cannot be empty' },
{ selector: 'select[name="wpcf-specialty"]', message: 'Specialty is required and cannot be empty' },
{ selector: 'input[name="wpcf-company-email"]', message: 'Your email is required and cannot be empty' }
];
// Remove any existing error messages.
jQuery('.validation-error').remove();
// Flag to track if any field has an error.
var errorsFound = false;
// Loop through each validation rule.
jQuery.each(validations, function(index, rule) {
if(rule.isRadio) {
// For radio groups, check if none is selected.
if(jQuery(rule.selector).length === 0) {
errorsFound = true;
// Insert error message before the first radio button in the group.
jQuery('input[name="wpcf-job-types"]').first().before('' + rule.message + '');
}
} else {
var field = jQuery(rule.selector);
// Check if the field is empty (trimming whitespace).
if(field.length && field.val().trim() === ''){
errorsFound = true;
// Insert error message above the field.
field.before('' + rule.message + '');
}
}
});
// If any errors were found, prevent form submission.
if(errorsFound){
e.preventDefault();
}
});
});