<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_filter('cred_form_validate','func_validate_my_form',10,2);
function func_validate_my_form($error_fields, $form_data) {
//field data are field values and errors
list($fields,$errors)=$error_fields;
if ($form_data['id']==117) {
if (empty($fields['wpcf-phone-number']['value']) and empty($fields['wpcf-wpcf-whatsapp-numbe']['value']) and empty($fields['wpcf-e-mail']['value']) ) {
$errors['wpcf-phone-number']='Please Enter at least One Value from Phone Number, Whatsapp or Email';
}
}
//return result
return array($fields,$errors);
this code is working for 1 form but I have mulitple form so need your help.
Hello. Thank you for contacting the Toolset support.
To apply the same code to multiple form IDs, you should try to use the following code:
add_filter('cred_form_validate','func_validate_my_form',10,2);
function func_validate_my_form($error_fields, $form_data) {
//field data are field values and errors
list($fields,$errors)=$error_fields;
$form_ids = array(117,118,119);
if (in_array($form_data['id'], $form_ids)) {
if (empty($fields['wpcf-phone-number']['value']) and empty($fields['wpcf-whatsapp-link']['value']) and empty($fields['wpcf-e-mail']['value']) ) {
$errors['wpcf-phone-number']='Please enter value for at least Phone,Email, Whatsapp';
}
}
//return result
return array($fields,$errors);
}
Where you can adjust the form ID with the given array: