Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ian 35 posts 135 karma points
    Apr 19, 2013 @ 16:58
    ian
    0

    searching for multiple words from a checkbox form

    hi,

    i am complete newby to umbraco and xslt, I hope someone can help. I have a checkbox form on my homepage passing through their values if selected eg "car" and "black". after submiting the form i then load the xslt search results page. If I just search for one word all is OK and the results are returned straight away without clicking the search button, however if I check more than one item the querystring returned is searchResults.aspx?search=car&search=black with no results returned. I think maybe the querystring need to change? can anyone help.

    i am using the latest version of umbraco v6 and xslt search

    thank you in advance

    ian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 19, 2013 @ 23:20
    Chriztian Steinmeier
    0

    Hi Ian,

    The QueryString thing is kind of standard form behavior (i.e., multiple fields with the same name are sent) - but they should be received as "car,black" to XSLTsearch, which I think must be an edge case use of this search package. You should be able to make it work, though - but we'll have to dig a little into the code to see how XSLTsearch does its magic...

    Can you maybe try to confirm that if you have some content that contains the sequence "car,black", that you are able to find it?

    /Chriztian

  • ian 35 posts 135 karma points
    Apr 22, 2013 @ 09:48
    ian
    0

    Hi,

    Thankyou for the reply.

    Yes I have the content to search for. If I manually change the querystring to search=car+black it finds the correct products.

    (I do pass in multiple fields with the same name from the original form)

    Ian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Apr 22, 2013 @ 09:54
    Chriztian Steinmeier
    0

    Hi ian,

    Oh - sorry, what I meant was - if you add the text "car,black" to a content page - does XSLTsearch then find that when you click those boxes? (Does the  searchResults.aspx?search=car&search=black then find the page?)

    /Chriztian

  • ian 35 posts 135 karma points
    Apr 22, 2013 @ 10:33
    ian
    0

    hi chriztian,

     

    I have just added new content (in the product document i have created a search tab with properites brand, colour to then select from a drop down list eg car and black when i add new product content) then tried to search for it with the form passing through search=car&search=black to searchResults.aspx and it still doesnt find anything. It does find the content if i only search for one item eg black

    Ian

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 29, 2013 @ 18:07
    Douglas Robar
    0

    Hi, Ian,

    XSLTsearch does an 'and' search if you have multiple terms to search for, but the assumption is that there is only a single search field.

    For instance, searchResults.aspx?search=car+black should work.

    The challenge, as Chriztian says, is that when multiple boxes are returned you get multiple entries, which doesn't work.

    I can think of two approaches:

    1. Use a bit of javascript/jQuery to concatinate search terms when the form is submitted. That is, ?search=car&search=black should become ?search=car+black when sent to XSLTsearch
    2. Modify XSLTsearch to handle this for you if multiple search terms are sent in. This would be done in the  <xsl:variable name="search"> section near the top of the xsltsearch.xslt file
    cheers,
    doug. 
  • ian 35 posts 135 karma points
    Apr 30, 2013 @ 12:43
    ian
    0

    Hi Doug,

    Thanks for the reply. I have used the jQuery method to alter the querystring and submitted that. It works great...

    How difficult would it be to change the search to an OR instead of AND? My xslt knowledge is basic...

    thanks again,

    Ian

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 30, 2013 @ 12:58
    Douglas Robar
    100

    Hi, Ian,

    Glad you got it sorted out.

    Adding an 'OR' search capability isn't particularly easy, particularly around scoring/ranking of results. Not impossible but a fair amount of work and you'd need to come up with some search syntax to allow it. XSLTsearch currently searches for all the terms as AND searches. Or, if a search term is in quotes it uses the quoted portion as an exact phrase.

    I'd thought of adding an OR capability but so few people use OR searches that it hasn't been worth the effort to build it into XSLTsearch. Perhaps you'll find it *is* worth the effort for your needs and will give it a shot :)

    cheers,
    doug. 

  • Jesper Georgsson 6 posts 26 karma points
    Jul 09, 2014 @ 09:45
    Jesper Georgsson
    0

    Hi!

    Ian, do you think you can post the jquery method you used for this? 
    I have the exact same issue. I would like /search/search=example&search=hello to be  /search/search=example+hello

    Been looking for a way but can't seem to find what I am looking for.

    Thanks,

    Jesper 

     

  • ian 35 posts 135 karma points
    Jul 09, 2014 @ 10:25
    ian
    0

    Hi Jesper,

    That's quite a while ago!

    Below is the code which generates the querystring from a checkbox form then sends to the browser.

    Hope it's of some use..

    function buildQueryString() {

     //setup the querystring
        querystring = "/searchResults.aspx?search=";
     //foreach checked checkbox on #searchForm append value to querystring
        $("#searchForm input[type=checkbox]:checked").each(function () {
            querystring = querystring + $(this).val() + "+";
        });

        window.location.href = querystring;  //send new querystring to browser

    }

     

    Ian

  • Jesper Georgsson 6 posts 26 karma points
    Jul 09, 2014 @ 11:38
    Jesper Georgsson
    0

    Thanks Ian,

    unfortunately it didn't help me.. I am stuck!

    Without your script:

    My box: <input type="checkbox" name="theme" value="Meat">Meat

    If i check a box, the value transcends to the url, like this:

    /receptsok/?search=test?theme=Meat
    

    What I would like is the url to be:

    /receptsok/?search=test+Meat
    

    Could I rewrite your script somehow, or do anyone have another example?

    Thanks, Jesper

  • ian 35 posts 135 karma points
    Jul 09, 2014 @ 12:07
    ian
    0

    Hi Jesper,

     

    My script should work, you will have to change the querystring value to your correct "xslt search results page" path / node then all it does it tag on the end the ?search= string and the selected checkboxes from your searchForm, again you will have to change the #ID to your actual html form ID.

    maybe something like: querystring="/receptsok.aspx?search=" then calling the function it will append the querystring to "/receptsok.aspx?search=meat + "any other checked checkbox"

    This is assuming you have a receptsok root node set with the xslt doctype.

    ian

  • Jesper Georgsson 6 posts 26 karma points
    Aug 14, 2014 @ 09:18
    Jesper Georgsson
    0

    Hi Ian!

    Back from vacation and had to dig into this again.. ;)

    I just made some kind of breakthrough. BUT still not exactly solved. I have set up the jquery you gave me and added a onClick to run the function when i submit my form. Now the values from the checkboxes works - but my search term gets lost somewhere. I guess because in the jquery I set the querystring = "/receptsok/?search="; which don't contains my search value. Do you have a tip how to also pass the search value together with the values from the checkboxes? :)

    Cheers, Jesper

  • Carlos 338 posts 472 karma points
    Sep 11, 2014 @ 23:15
    Carlos
    0

    @Jesper.  We just did this.  You would check all or each checkbox and use jQuery .join() as you option.

     

    Here is what we used.  Pretty much we bypass the XSLTsearch form button altogether and just pass in our query string. 

    <script type="text/javascript">
     $(document).ready(function() {
    
         $("*").zInput();//Good jQuery plugin to use if you want to change your checkboxes into styled div boxes.
    
    
        $("span#programSelect").click(function (event) { //Using a span to do our form submission.
    
            var tmp = [];  //create our array
            //$('.zInput.zCheckbox.zSelected input').each(function(){ // used with the zInput plugin. Ignore if you don't want to use this
    //Just your basic lookup for checked checkboxes
    $(div#searchForm input[type=checkbox]:checked]) tmp.push($(this).val()); // will get the value of each checkbox }); var result = tmp.join('+'); // creates your query string and joins together with the '+' sign //alert(result); window.location.href = '/my-page?search=' + result; }); }); </script>
Please Sign in or register to post replies

Write your reply to:

Draft