#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    64
    Rep Power
    6

    Modifying form action for Google Search Appliance


    I'm attempting to create a custom HTML form which submits the query to the Google Search Appliance. The results are displayed in an iframe.

    Problem being is the action from the form:
    http://search1.dot.state.mn.us/search?q=test&btnG=Search&site=clips01&site=clips02&client=newsline&output=xml_no_dtd&proxystyleshee t=newsline&getfields=*&filter=0&num=5&proxyreload=1

    I have multiple collections and I need to search across them based on the check-boxes the user selects.Problem is the:

    &site=clips01&site=clips02&site=clips03&site=clips04
    Needs to be:
    &site=clips01|clips02|clips03|clips04

    I currently have this:
    Code:
    $(document).ready(function() {
      $('#newsclips').submit(function() {
        //Get the values from the form and place them in a string
        var values = $(this).serialize();
    
        //Change the values for &site= ???
    
        //Modify the action of the form
        var action = "http://search1.dot.state.mn.us/search?" + values;
        $(this).attr('action', action);
    }); });
    Not sure if this is the best way, I figured I could do a search & replace on the string after it was serialized. I couldn't figure out how to get it to work correctly so I stripped it out of the code I currently have and looking for a better way. Any ideas?

    This is the full string being sent in the action:
    Code:
    http://searchappliance/search?q=test&btnG=Search&site=clips01&site=clips02&client=newsline&output=xml_no_dtd&proxystylesheet=newsline&getfields=*&filter=0&num=5&proxyreload=1
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    64
    Rep Power
    6

    Update!


    So I'm using this code and the alerts look correct, but it doesn't seem to be actually modifying the "action" attribute correctly. If I change "searchappliance" to "testsearchappliance" that seems to work correctly, but the parameters after it are not being set correctly. It's like the form is over-writing my action somehow?

    **Update - Ok, so what I believe is occurring is the action is correctly updated, but the way the form works is that it overwrites anything past the "search?" with the parameters on the form before submitting it to the iframe.

    I attempted to "event.preventDefault()" but that just puts it into and endless loop as the function itself is an event listener. Even if I add another submit() at the bottom of the script. So now I think I know what is occurring, just not sure how to resolve it.

    This site, URL re-write using PHP for Google Search Appliance , shows how to do it using PHP which I may have to switch to. Not sure how it will work with an iFrame on the page.

    Code:
    $('#newsclips').submit(function(event) {
      //Get the values from the form and place them in a string
      var values = $(this).serialize();
      alert (values); 
    
      //Modify the values to remove the &site=
      values = values.replace(/&site=/ig,'|');
      values = values.replace(/\|/i,'&site=');
      alert (values);
    
      //Modify the action of the form 
    
      var newAction = "http://searchappliance/search?" + values;  
      $(this).attr('action', newAction);
      alert (newAction);
    });
    Last edited by foxtail; December 24th, 2012 at 03:28 PM.

IMN logo majestic logo threadwatch logo seochat tools logo