View Full Version : Search form post to new page's iframe?

12-02-2006, 01:58 AM
Ok try to bear with me here...

I have a site where 80% of it is being fed in through iframes from another page (yes mine but i wanted a custom design for a vendor supplied product search site).

The categories on the left nav opens a new dedicated page with an iframe in it containing the link from my vendor site so basically a looong search query URL like


Now I want to be able to perform a search from any page in a search box i'm putting into the header.

From any page, I want to have the search box results open in a new page like /search/ and have the results post in that page's iframe.

Is this possible? If so how do I accomplish this with php

Currently I have an invisible iframe named 'keywordsearch' on every single page with no source and if the search box is filled out it opens the iframe with z-index:100 over the current page's content... icky I know but frames suck.

Thanks much for your help.

12-02-2006, 05:15 AM
In order to do what you want to do, I think you;d literally need to open up every page that you want searchable on your vendor's site, and search each remote file for the search keyword(s). When a match was found, you would need to record the file name that the match was found in, and probably capture some of the context text surrounding the keyword match. Then take all of this info and build your pseudo-iframe (I say pseudo, because this iframe will link to content on your server) on your search page. In fact you don;t even need a real iframe here; you could use some CSS to simulate an iframe. (that way you only need one file, not two). Finally, Use the information you compiled earlier to build the links in your search results (inside the pseudo-iframe on your search page).

So anyway, my general approach for this would be to:

1) Your search box on every page of your site would send POST information to your search results page, let's call it search.php.

2) on search.php, create an array that contains all of the remote files that you want to search.

3) Loop through your array, and use file_get_contents() on each URL to get that URL's contents, search each page's contents with some regex, and fill an array with the results:


$file_array = array('my_home.php' => 'index.php','my_products.php' => 'products.php','my_services.php' => 'services.php'); // where the keys are your pages, and the values are the vendor's pages on your corresponding "key" pages
$pattern = '/(.{0,100}?)('.preg_quote($_POST['search_phrase'],'/').')(.{0,100})/i)';
results = array();

foreach ($file_array as $key => $val)
$contents = file_get_contents("http://www.vendorSite.com/".$val);
$contents = strip_tags($contents);
if (!empty($matches[2]))
foreach (matches[2] as $k => $v)
$results[x]['blurb'] = "..." . $matches[1][$k] . '<font color="#FF0000"><b>' . $matches[2][$k] . "</b></font>" . $matches[3][$k] . "...";
$results[x]['file'] = $key;
}4) Then you iterate through the $results array inside your pseudo iframe (I think creating a CSS iframe look-alike is your best bet), and display the results links however you want (the following is just a simple example):

foreach ($results as $key => $val)
echo "<p>$y) <a href='http://www.yourSite.com/".$results[$key]['file']."'>".$results[$key]['file']."</a></p>";
echo "<p>".$results[$key]['blurb']."</p><br />";
}I didn;t test any of this -- just trying to give you a direction to run with. Good luck!