PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Dynamic Creating Conditional Logic

  1. I've created a drop list and populated it dynamically using it's Choices from a set of data we hold in our database. I have a couple of fields that I want to hide or show based on the drop down list values so I need to dynamically create conditional logic for this. Can you post a example of this in action please. I've used the conditional logic before using the form designer, but now i need to create that myself within the form.

    Regards

    Ben

    Posted 8 years ago on Tuesday January 10, 2012 | Permalink
  2. 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];
    if($value!=null)
    $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?

    Regards

    Ben

    Posted 8 years ago on Wednesday January 11, 2012 | Permalink
  3. Pete
    Member

    Hi Ben.

    This is exactly what i am looking for.
    I´m a php and sql beginner, so is it possible for you to show me what you have done to achieve this - like how do the code you put in the function.php look like.

    Thanks
    Peter

    Posted 8 years ago on Thursday January 12, 2012 | Permalink