Hello,
Thanks for the feedback! Unfortunatly this cannot be done via the Advanced Validation UI, for now. I plan to add in the future, but for now you’ll have to rely on the acf/validate_value
hook. See documentation: https://www.advancedcustomfields.com/resources/acf-validate_value/
This hook is not really perfect to validate a field against an another one, since it’s quite isolated, and you’ll have to rely on the $_POST['acf']
array to check the other field value.
If you’re using the Dynamic Forms module for the front-end form, you can use acfe/form/validation
hook, which is more simple. See documentation.
This hook let you easily validate any field against an another. Here is a usage example:
add_action('acfe/form/validation/form=my-form', 'my_form_validation', 10, 2);
function my_form_validation($form, $post_id){
// Get field input value
$my_field = get_field('my_field');
$my_field_2 = get_field('my_field_2');
if($my_field !== $my_field_2){
// Add global validation error
acfe_add_validation_error('', 'My Field is different from My Field 2');
}
}
Hope it helps!
Regards.