Conditional Logic - Redirect based on list of numbers

Hi All,

So I am trying to create or adapt this code which currently redirects a form submission / confirmation to a URL.

It currently redirects IF the number entered is 10. (which I can do via the back end of GF in conditional logic)

However… I need to input a list of around 50 random numbers instead of just the number 10.

Any ideas if this can be done?

Code I have so far is below… and the link to the snippet page is here - https://gravitywiz.com/conditional-confirmations/

/**

  • Conditional Confirmations (with Merge Tag Support)
  • Provides the ability to register conditional confirmations. To register a new conditional confirmation
  • use the GWConditionalConfirmations::add_conditional_confirmation() function.
  • GWConditionalConfirmations::add_conditional_confirmation($form_id, $field_id, $operator, $value, $confirmation);
  • @param mixed $form_id The ID of the form for which you would like to register a conditional confirmation.
  • @param mixed $field_id The field ID of the field for which you would like to base the confirmation condition.
  • @param mixed $operator The operator which will be used to compare the submitted field value against the specified value
  • passed in the $value parameter. Accepted values are “is”, “isnot”, “greater_than”, “less_than”, “contains”, “starts_with”, “ends_with”
  • @param mixed $value
  • @param mixed $confirmation Accepted values are:
  • array(‘redirect’ => ‘http:://yoururl.com’)
  • array(‘page’ => 12)
  • ‘Plain text confirmation!’
  • @param $do_init Defaults to true. Will automatically run the init which will trigger the conditional functionality when the
  • form is submitted. If you would like to init on your own, you can pass false here and call the GWConditionalConfirmation::init()
  • function anytime before the gform_confirmation hook is called.
    */

class GWConditionalConfirmations {

public static $init = false;
public static $confirmations = array();

public static function init() {
    add_filter('gform_confirmation', array( __class__, 'get_conditional_confirmation'), 6, 4);
}

public static function add_conditional_confirmation($form_id, $field_id, $operator, $value, $confirmation, $do_init = true) {
    
    if(!self::$init && $do_init) {
        GWConditionalConfirmations::init();
        self::$init = true;
    }
    
    if(!isset(self::$confirmations[$form_id]))
        self::$confirmations[$form_id] = array();
    
    $confirmation['gwConditionalLogic'] = array('field_id' => $field_id, 'value' => $value, 'operator' => $operator);
    array_push(self::$confirmations[$form_id], $confirmation);
    
}

public static function get_conditional_confirmation($confirmation, $form, $lead) {
    
    if(!isset(self::$confirmations[$form['id']]))
        return $confirmation;
    
    foreach(self::$confirmations[$form['id']] as $conf) {
        if(self::is_condition_met($form, $conf['gwConditionalLogic']))
            return self::convert_confirmation($conf, $form, $lead);
    }
    
    return $confirmation;
}

public static function is_condition_met($form, $condition) {
    
    $field = RGFormsModel::get_field($form, $condition['field_id']);
    $is_visible = !RGFormsModel::is_field_hidden($form, $field, array());
    $field_value = apply_filters('gw_condition_field_value', RGFormsModel::get_field_value($field, array()) );
    $is_value_match = RGFormsModel::is_value_match($field_value, $condition['value'], $condition['operator']);

    return $is_value_match && $is_visible;
}

public static function convert_confirmation($confirmation, $form, $lead) {
    // if redirect is set, return as is
    if(isset($confirmation['redirect'])) {
        $confirmation['redirect'] = GFCommon::replace_variables( trim( $confirmation['redirect'] ), $form, $lead, true );
        return $confirmation;
    // if page is set, return as redirect with permalink
    } else if(isset($confirmation['page'])) {
        return array('redirect' => get_permalink($confirmation['page']));
    // if nothing else, assume it is text and wrap in the confirmation HTML
    } else {
        return "<div id='preview_form_container'>" . GFCommon::replace_variables($confirmation, $form, $lead, true) . "</div>";
    }
}

}

// example for form ID 7 where the confirmation will redirect the user to http://google.com if the value of field ID 3 is less than 10
GWConditionalConfirmations::add_conditional_confirmation(6, 4, ‘contains’, 10, array(‘redirect’ => ‘URL GOES HERE’));