Leading and trailing spaces in text search fields cause search to fail

Home Forums Menubar Forum Leading and trailing spaces in text search fields cause search to fail

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #11063 Reply
    James
    Guest

    When a space is included at the beginning or end of a text field (whether accidentally or on purpose), it’s included in the search string.

    I think this may be confusing for users, who would expect that leading/trailing spaces be removed from the search query, and so may be surprised that their search term doesn’t match.

    If this isn’t something which could be included in the plugin code, could the author please let me know where is a sensible place to add this code in myself?

    Thank you! This is a not very often used feature for us but when we do need it it’s extremely useful and valuable, so thank you!

    #11065 Reply
    andrea
    Keymaster

    Hi James,

    Leading and trailing spaces are included in the search string by design but, if you wish to remove them, you can add this code to your bp-custom.php file:

    add_filter ('bps_request', 'trim_values', 10, 3);
    function trim_values ($request, $type, $form)
    {
    	$key= 'field_45_contains';
    	if (isset ($request[$key]))
    		$request[$key] = trim ($request[$key]);
    	return $request;
    }

    Replace 45 with the actual ID of the field you want to trim.

    #11066 Reply
    James
    Guest

    Thanks, that works exactly as I need, appreciate the fast response

    #11067 Reply
    andrea
    Keymaster

    You are welcome!

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Leading and trailing spaces in text search fields cause search to fail
Your information: