Trim whitespace on search input field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 22, 2018   (RSS)

By leo - May 22, 2018

Hi Greg,

I think it doesn't need to be modified, because if the user input "television " he might be looking for records like "television cable" or anything that contains television but not exactly television.

However, if you still want to modify the search query, rtrim() may be the function you need: http://php.net/manual/en/function.rtrim.php

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

By gversion - May 22, 2018

Thanks, Leo!

I was trying to get the form to remove the trailing whitespace using JS with the following code:

    <script>
      $('#search_submit_button').click(function(){
      var text = $('#search-desktop').val();
      text = text.trim();
      $('#search-desktop').val(text);
      $("#header-search").submit();
      });
    </script>

Seems to be working ok...!

Regards,

Greg