If no text is entered into a text-type exposed form field, then the filter will still add "... LIKE UPPER('%%') ..." to the WHERE clause when using the contains operator. In addition, there is no option to make this text filter optional. I have tracked down this problem and it is being caused in views_handler_filter_string.inc. There, the contains operator is being hardcoded to never be optional.

The piece of code that causes this issue was added in response to #534452: Exposed filters are always optional. In that issue, the problem was about how the contains text filter has an 'optional' checkbox that when left unchecked, should imply that it is required. This meant that users were free to search with no filters and get results that contain every single entity in the system.

-- I have confirmed that this issue is still fixed even with the introduction of my patch.

  1. if a text-type exposed form field has the optional checkbox unchecked, then the WHERE clause is still added (which ensures that the value is required -- NOT NULL).
  2. if a text-type exposed form field has the optional checkbox checked AND there is no value passed to the filter, then the WHERE clause is omitted.

Issues that are potentially related to this problem (different Views versions):
#1109784: Null CCK fields are always excluded when using an exposed 'contains' filter.
#534452: Exposed filters are always optional
#1054272: String filters are non optional anymore

CommentFileSizeAuthor
#1 1958378-text-filter-optional.patch622 bytesmark.lindsey

Comments

mark.lindsey’s picture

StatusFileSize
new622 bytes

Attached patch to 6.x-2.x to fix this.

chris matthews’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

The Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue