Page 1 of 1

PHP search external site with internal search engine

Posted: Fri Apr 24, 2009 4:25 pm
by aerocontroller
Hi,
I am trying to create a very simple php application that will search a specific external site. I am trying to learn php but this is the first project i have ever attempted. I need to have a simple text box and submit buttom with an iframe below. I want to be able to type search criteria into the textbox and when you press search it takes the specified criteria and places it after this url "http://www.globalplanesearch.com/isapis/srch.dll?gpsq=".

ex. if you typed "aircraft" into the textbox and hit search, then the url would become:
"http://www.globalplanesearch.com/isapis ... q=aircraft"
and then it would make the iframe display the url.

I was wondering if someone could help me do this. ive never done php before but i am very good with html,css and i can read and understand some php but not enough to know the syntax.

any help would be greatly appreciated
Thanks!
-Shawn

Re: PHP search external site with internal search engine

Posted: Fri Apr 24, 2009 4:27 pm
by aerocontroller
Im not bumping i just wanted to see if the system will email me updates when someone replies to this topic

Re: PHP search external site with internal search engine

Posted: Sat Apr 25, 2009 11:24 pm
by McInfo
Here is a Javascript solution.

Code: Select all

<html>
<head>
<title>Iframe Search</title>
<script type="text/javascript">
function search ()
{
    var term = get('gpsq').value;
    if (term == '')
    {
        alert('Enter a search term.');
        return false;
    }
    else
    {
        get('searchFrame').src = 'http://www.globalplanesearch.com/isapis/srch.dll?gpsq=' + term;
        return true;
    }   
}
function get (id)
{
    return document.getElementById(id);
}
</script>
</head>
<body>
 
<form method="get" action="http://www.globalplanesearch.com/isapis/srch.dll" onsubmit="search(); return false;">
    <input type="text" id="gpsq" name="gpsq" value="" size="30" />
    <input type="submit" value="Search" />
</form>
 
<iframe id="searchFrame" src="" style="width: 100%; height: 200px; border: solid 1px #888;"></iframe>
 
</body>
</html>
If the client has Javascript enabled, the form is prevented from being submitted normally. Instead, the Javascript captures the search phrase and changes the iframe's src attribute. This causes a request to be sent to the search site and the results page is shown in the iframe.

If the client does not have Javascript enabled, the form falls back on the action attribute. The form is submitted directly to the search page and the client leaves your page to go to the search results page.

Edit: This post was recovered from search engine cache.