Hi @candlelite
I hope you’re well today and thank you for your question!
Currently there is no conditional logic support for comparing two or more fields yet. You can compare field against some value but not against another field value. This is something that we do plan to add to the plugin in future but I don’t have ETA.
For now, you can use this additional code snippet to achieve this:
<?php
add_filter( 'forminator_custom_form_submit_errors', 'compare_fields_submission_filter', 99, 3 );
function compare_fields_submission_filter( $submit_errors, $form_id, $field_data_array ) {
$forms = array( 3010 ); // IDs of forms to check; if more than one, separate by comma
$field_a = 'name-1';
$field_b = 'name-2';
$error_msg = 'Incorrect values!';
// DON'T EDIT BELOW
if ( !in_array( $form_id, $forms ) ) {
return $submit_errors;
}
$field_a_value = '';
$field_b_value ='';
foreach( $field_data_array as $arr ) {
if ( $arr['name'] == $field_a ) $field_a_value = $arr['value'];
if ( $arr['name'] == $field_b ) $field_b_value = $arr['value'];
}
if ( ( !empty( $field_a_value) ) && ( !empty( $field_b_value) ) ) {
if ( $field_a_value === $field_b_value ) {
$submit_errors[][$field_b] = $error_msg;
}
}
return $submit_errors;
}
You’d need to add it to the site as MU plugin:
– create an empty file with a .php extension (e.g. “forminator-compare-fields-filter.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install on the server
– copy and paste code into it and save it.
You’ll also need to adjust these four lines in the code:
$forms = array( 3010 );
$field_a = 'name-1';
$field_b = 'name-2';
$error_msg = 'Incorrect values!';
where accordingly:
– in first, replace the 3010 number with your form ID (form ID is the number you see in form shortcode)
– in second and third – adjust fields’ IDs if necessary
– in fourth you can set your own error message.
Best regards,
Adam