diff --git a/gravity-forms/gw-conditional-logic-operator-does-not-contain.php b/gravity-forms/gw-conditional-logic-operator-does-not-contain.php new file mode 100644 index 00000000..f96ddbdc --- /dev/null +++ b/gravity-forms/gw-conditional-logic-operator-does-not-contain.php @@ -0,0 +1,172 @@ + + + is_applicable_form( $form ) && ! has_action( 'wp_footer', array( $this, 'output_script' ) ) ) { + add_action( 'wp_footer', array( $this, 'output_script' ) ); + add_action( 'gform_preview_footer', array( $this, 'output_script' ) ); + } + + return $form; + } + + public function output_script() { + ?> + + is_applicable_form( $form ) ) { + return; + } + + $script = 'new GWCLODoesNotContain();'; + $slug = implode( '_', array( 'gwclo_does_not_contain', $form['id'] ) ); + + GFFormDisplay::add_init_script( $form['id'], $slug, GFFormDisplay::ON_PAGE_RENDER, $script ); + } + + public function whitelist_operator( $is_valid, $operator ) { + if ( $operator === 'does_not_contain' ) { + $is_valid = true; + } + return $is_valid; + } + + public function evaluate_operator( $is_match, $field_value, $target_value, $operation, $source_field, $rule ) { + + if ( $rule['operator'] !== 'does_not_contain' || rgar( $rule, 'gwclodncEvaluatingOperator' ) ) { + return $is_match; + } + + $rule['gwclodncEvaluatingOperator'] = true; + + // If the field contains the target value, it's not a match. + $is_match = strpos( $field_value, $target_value ) === false; + + $rule['gwclodncEvaluatingOperator'] = false; + + return $is_match; + } + + public function convert_conditional_logic_to_field_filters( $field_filters ) { + + foreach ( $field_filters as &$field_filter ) { + if ( ! is_array( $field_filter ) ) { + continue; + } + + switch ( $field_filter['operator'] ) { + case 'does_not_contain': + $field_filter['operator'] = 'NOT LIKE'; + $field_filter['value'] = '%' . $field_filter['value'] . '%'; + break; + } + } + + return $field_filters; + } + + public function is_applicable_form( $form ) { + return GFFormDisplay::has_conditional_logic( $form ); + } +} + +# Configuration + +new GF_CLO_Does_Not_Contain();