Site A: in development (PHP) Site B: http://www.apprenticesearch.com/
I want to include an input box on site A; after I type in the query and press Enter, open a new tab to display the search results of B. It would be as if I had typed the search query into B directly.
For example I searched for 'testing', and inspecting the search result from B, I see the following. How would I pass the query from site A to B?
<div id="search">
<form action="/Resources/SiteSearch" id="siteSearchForm" method="post">
<label for="search-box">
SEARCH</label>
<div id="search-box-wrapper">
<input type="text" id="search-box">
</div>
<input id="searchText" name="searchText" type="hidden" value="testing"><input id="siteSearchUrl" name="siteSearchUrl" type="hidden" value="http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q=testing">
<input type="image" src="/userfiles/images/E/buttons/go.png" id="search-button" value="GO" siteurl="www.apprenticesearch.com"><!-- www.apprenticesearch.com -->
</form>
</div>
All you need to do is include a target="_blank" in the form on Site A, also the way that the request works on site B the siteSearchUrl input must be included
<form id="apprenticeForm" action="http://www.apprenticesearch.com/Resources/SiteSearch" method="POST" target="_blank" onsubmit='submitSearch()'>
<input type="text" name="searchText" id="searchText" value=""/>
<input type="submit" value="Submit"/>
<input id="siteSearchUrl" name="siteSearchUrl" type="hidden" value="http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q="/>
</form>
Like this http://jsfiddle.net/MVBLc/
After playing around with the form submitting, but the q parameter not being read by Site B, I believe it's because the input had escaped &
instead of '&'.
I've updated the HTML, and here's the javascript to update the field before submitting the form
function submitSearch()
{
q = document.getElementById("searchText").value;
document.getElementById("siteSearchUrl").value = 'http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q=' + q;
return true;
}
The reason you need to use javascript for the additional input is the same reason why Site B uses javascript to populate siteSearchUrl in their script before it sends the request.
Looking at how the server works: Site B sends that request to /Resources/SiteSearch where the SiteSearch(String searchtext, String siteSearchUrl)
function gets called on their server. If you were to just go straight to that page with no post parameters you will find that a System.ArgumentNullException Parameter name: uriString
is thrown for not having siteSearchUrl set from the server.
If you want to analyze the parameters of siteSearchUrl:
yboss.yahooapis.com
is for Yahoo's BOSS API servciesites
parameter tells the API what site to search and display in the resultsq
parameter is what query to search for