I worked it out and put it in a generic function to use.
$rules = array();
for($i = 0; $i<count($showarray); $i++)
$value = $showarray[$i];
$rules = array('fieldId' => $fieldid, 'operator' => 'is', 'value'=>$value);
$field['conditionalLogic'] = array('actionType' => 'show','logicType' => 'any','rules' => $rules);
Pretty basic, the $showarray holds an array of text items that the 'fieldId' ($fieldid) can be to show the field. I have written a similar function to hide as well, but I think there is an issue with GravityForms. I set the $field up with the property of being required and I expected this to be ignored when the field was hidden just as when you add conditional logic using the UI. However when I add the conditional logic dynamically as above the fields are hidden as expected but when the form is submitted it can't be because a hidden field from the conditional logic is halting the operation because of the required property of it.
If this a bug, or is there another way of setting the conditional logic dynamically on required fields so it works correctly?
Posted 10 years ago on Wednesday January 11, 2012 | Permalink