...

View Full Version : Search function from external source to show results on our site



pruocco
07-27-2012, 07:17 PM
I work for a promotional products company and we use a database called Sage which brings together all products from all different companies into one easy-to-use search function.

They supplied us our own "online storefront" which visually sucks. So I decided to try and use their search function on our main website.

I viewed their source and took what I needed to make the search functional on our website. This is the code:


<form method="GET" action="http://www.promoplace.com/ws/ws.dll/StartSrch" onsubmit="return Form_Validator(SrchCrit)" name="SrchCrit">
<input type="hidden" name="DistID" value="27738">
<input type="hidden" name="ProdSelect" value="">
<input type="hidden" name="Srching" value="1">
<input type="hidden" name="CatName" value="">
<input id="search-button" type="submit" value="" alt="Start Search!" onMouseOver="window.status='Start your search';return true" onMouseOut="window.status='';return true;">
<input type="text" id="search-field" name="keywords">
<input type="hidden" name="GlobalSearch" value="">
</form>
What I would like to do is have the results open on one of our website's pages... with our header, links, etc. even if the solution is a blank page with an iFrame and the results loaded inside of it.

Is there a way to go about this?

Thank you in advance for any help.

stevenmw
07-28-2012, 02:35 AM
Just code the form to use a seperate php page to process the search and display it. Make sure to design the page with the iframe, and whatever else you want. The display the results using a while loop where ever in the page you want.

This is border line web projects category material.

pruocco
07-30-2012, 01:46 PM
Thank you for the reply and I apologize if this should be in another category.


The display the results using a while loop where ever in the page you want.

Could you give me an example of this part? I don't know much about it. I would appreciate it very much.

pruocco
08-13-2012, 09:11 PM
I am still trying to figure out this issue. If anyone has any other suggestions or can write me up an example, that would be an enormous help.

AndrewGSW
08-13-2012, 09:39 PM
This is just a rough draft but:

Re-direct the form submission to your own page, which contains an iframe that will display the search results;
Your new page will contain all your headers, links, etc., plus the iframe, and code to process the search data - that is, to obtain the results from promoplace.com and display them in the iframe.


<!-- pagea.html -->
<form method="GET" action="pageb.html" onsubmit="return Form_Validator(SrchCrit)" name="SrchCrit">
<input type="hidden" name="DistID" value="27738">
<input type="hidden" name="ProdSelect" value="">
<input type="hidden" name="Srching" value="1">
<input type="hidden" name="CatName" value="">
<input id="search-button" type="submit" value="" alt="Start Search!" onMouseOver="window.status='Start your search';return true" onMouseOut="window.status='';return true;">
<input type="text" id="search-field" name="keywords">
<input type="hidden" name="GlobalSearch" value="">
</form>



<!DOCTYPE html><!-- pageb.html -->
<html>
<head>
<title>Document Title</title>
<script type="text/javascript">
function loadIframe() {
if (location.search.length > 0) {
searchargs = decodeURIComponent(location.search.substring(1));
document.getElementById("myiframe").src = "http://www.promoplace.com/ws/ws.dll/StartSrch?" +
encodeURIComponent(searchargs);
} else {
document.getElementById("myiframe").src = "defaultpage.html";
}
}
window.onload=loadIframe;
</script>

</head>

<body>
<iframe name="myiframe" id="myiframe" src=""></iframe>
</body>
</html>

pruocco
08-13-2012, 09:57 PM
Thank you very much for the reply, AndrewGSW.

I did everything you said but its giving me an error when i submit the search. The error comes from SAGE (who runs promoplace) saying that the address is missing. I think it has something to do with
document.getElementById("myiframe").src = "http://www.promoplace.com/ws/ws.dll/StartSrch?" +

If you go to our "behind the scenes" site (http://033691f.netsolhost.com/stnew/screentek/index.php), youll see two search bars. The top one is the original one I had which opened the results in its own page, no headers etc. The second is using your code. Maybe you can find something between the two that helps.

AndrewGSW
08-13-2012, 10:04 PM
You can't have two forms of the the same name on the same page. The data that is being passed is probably largely taken from the first form.

Delete the first form temporarily.

pruocco
08-13-2012, 10:07 PM
Ok, removed but no change.

AndrewGSW
08-13-2012, 10:16 PM
Ok, removed but no change.

I copied the form details from your original post. Did some of those hidden fields have values that you removed from the code that you posted? I'm assuming they all (possibly) require values.

tempz
08-13-2012, 10:50 PM
Try: http://www.google.com/cse/manage/create

pruocco
08-14-2012, 02:11 PM
I copied the form details from your original post. Did some of those hidden fields have values that you removed from the code that you posted? I'm assuming they all (possibly) require values.

No, those values were like that when I copy/pasted the code.

This is the page I copied the code from. http://www.promoplace.com/ws/ws.dll?DistID=27738
27738 being our customer ID.

pruocco
08-15-2012, 03:41 AM
Nope, i did not change any values. Simply copy pasted the form and took out the fields i didnt want to use (ie category, theme, etc.) leaving just the keyword field and the submit button.

AndrewGSW
08-15-2012, 01:28 PM
Sorry, but the address you entered is not valid. (SAGE WebStore ERR:Missing or invalid ID)

That error message is coming from SAGE. The info being passed to the iframe is:


DistID=27738&ProdSelect=&Srching=1&CatName=&keywords=asearchterm&GlobalSearch=
so there seems to be something missing from these terms that SAGE requires. But the message seems quite specific in requiring a (correct) ID.


<form method="GET" action="results.php" onsubmit="return Form_Validator(SrchCrit)" name="SrchCrit">

I think you should include the function Form_Validator() on the first page, even if it just does 'return true'. Alternatively, remove this part: onsubmit="..." temporarily.

pruocco
08-15-2012, 04:30 PM
I think you should include the function Form_Validator() on the first page, even if it just does 'return true'. Alternatively, remove this part: onsubmit="..." temporarily.

I'm a noob with JavaScript, I'm not sure how to do this correctly. I removed the onsubmit="..." but no change. The ID is correct, I just verified it with my boss.

It's weird though - the search worked fine when it was on it's own page, no iFrame. Now it doesn't work, but nothing was changed or added except the javascript and iFrame itself. I would assume that there is something going wrong during the redirection to the iFrame, but I really have no idea. Just a guess.

Please dont give up on me, lol.

AndrewGSW
08-15-2012, 05:45 PM
if (location.search.length > 0) {
searchargs = decodeURIComponent(location.search.substring(1));
document.getElementById("myiframe").src = "http://www.promoplace.com/ws/ws.dll/StartSrch?" +
encodeURIComponent(searchargs);
} else {
document.getElementById("myiframe").src = "defaultpage.html";
}

Try deleting the word encodeURIComponent. If not, try also deleting decodeURIComponent. I suspect it's the encoding..

pruocco
08-15-2012, 08:58 PM
if (location.search.length > 0) {
searchargs = decodeURIComponent(location.search.substring(1));
document.getElementById("myiframe").src = "http://www.promoplace.com/ws/ws.dll/StartSrch?" +
encodeURIComponent(searchargs);
} else {
document.getElementById("myiframe").src = "defaultpage.html";
}

Try deleting the word encodeURIComponent. If not, try also deleting decodeURIComponent. I suspect it's the encoding..

By deleting "encodeURIComponent" the search worked but took a while for it to complete. By removing both, the search worked perfectly! Is it okay to remove the encoding like that?

AndrewGSW
08-15-2012, 09:29 PM
Is it okay to remove the encoding like that?

Yes. It's not a security feature as such, but is used to prevent invalid, or unexpected, characters being added to the url. Browsers these days tend to cope with these characters better than they used to, particularly spaces.

However, there is nothing to prevent anyone typing directly into the browser's address bar. So it is possible for someone to display different results in your iframe.

But it is a reasonable expectation that promoplace will reject any invalid request - as we've already seen!

Added: Of more concern is that your DistID is clearly visible within your page :)

pruocco
08-15-2012, 10:03 PM
Yes. It's not a security feature as such, but is used to prevent invalid, or unexpected, characters being added to the url. Browsers these days tend to cope with these characters better than they used to, particularly spaces.

However, there is nothing to prevent anyone typing directly into the browser's address bar. So it is possible for someone to display different results in your iframe.

But it is a reasonable expectation that promoplace will reject any invalid request - as we've already seen!

Added: Of more concern is that your DistID is clearly visible within your page :)

We have a slash address with promoplace (www.promoplace.com/screentek). Is there anything you can do with that to replace the DistID? If not I don't think it's that big of a deal since you would need the password to do anything anyway.

Either way, thank you so much for your help. My boss and I are both very appreciative!

AndrewGSW
08-15-2012, 11:53 PM
I don't know about the slash address and how this might help. But, as you state, the DistID on its own does not pose any risk.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum