My goal is to give a warning when the state does not match another field or alternatively it does not match a page custom field.
I’ve tried a couple different ways but I’m confused about some things.
With this example,
add_filter( 'gform_pre_render', 'set_conditional_logic' );
add_filter( 'gform_pre_process', 'set_conditional_logic' );
function set_conditional_logic( $form ) {
//Set conditional logic only for form 14
if ( $form['id'] !== 14 ) {
return $form;
}
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 2 ) {
$field->conditionalLogic =
array(
'actionType' => 'show',
'logicType' => 'all',
'rules' =>
array( array( 'fieldId' => 1, 'operator' => 'is', 'value' => 'First Choice' ) )
);
}
}
return $form;
}
I have trouble with the ‘value’ => ‘First Choice’))
I can’t seem to get it to find the value from another field. Alternatively I could compare the value against a custom field in the page meta but I can’t get it to find the page id that the form is currently on. I think because it may be outside the loop?
So I tried gform_is_value_match
My problem here is I don’t see where the comparison field id goes in this javascript example,
`gform.addFilter(` `'gform_is_value_match'` `, ` `function` `(isMatch, formId, rule) {`
` ` `// do stuff`
` ` `return` `isMatch;`
`} );`
And finally, in the PHP example, it includes a comparison of conditional logic views. I can’t quite figure out how to do just a comparison of values in this example.
`add_filter( ` `'gform_is_value_match'` `, ` `function` `( ` `$is_match` `, ` `$field_value` `, ` `$target_value` `, ` `$operation` `, ` `$source_field` `, ` `$rule` `) {`
` ` `// do stuff`
` ` `return` `$is_match` `;`
`}, 10, 6 );`
I may not need to do the PHP part. Any help is appreciated. If it’s too much I’ll just keep trying to figure it out. Thank you.