Help - Search - Members - Calendar
Full Version: Search
Movable Type Community Forum > Additional Resources > Tips and Tricks
Mr. Adams
How can I give visitors to my site the option to search either "my site" or "googles" using 1 search input form? thanx all
girlie
Hmmm, I'm not sure how that would work, since there are two different "actions" involved:

CODE
<form method="get" action="http://www.google.com/search">

<form method="post" action="<$MTCGIPath$><$MTSearchScript$>">


I thought you could only have one action statement per form, but maybe someone else knows otherwise.

I'd be interested to find out for sure!!
Mr. Adams
I've seen it on a MT powered site before but don't remember which...It was set up to where you choose a radio button to search your MT site or googles. So I know it can be done.
faf
Here's a sample script i just thought up. this requires PHP on your server, and a browser that supports javascript though.

CODE
<FORM METHOD="POST" ACTION="search.php">
<INPUT TYPE="text" NAME="query" SIZE="30"><br>
<INPUT TYPE="radio" NAME="engine" VALUE="MT" checked>Journal Entries
<INPUT TYPE="radio" NAME="engine" VALUE="google">All of Site (using google)<br>
<INPUT TYPE="submit">
</FORM>

<?php

if (isset($query)) {
    if($query != "") {
    dosearch ($engine,$query);
}
else {
echo "stop mucking about, you nonce!";
}
}

function dosearch ($engine,$query) {

if ($engine == "MT") {
echo "<script>";
echo "window.location = 'http://www.dotfaf.com/cgi-bin/mt/mt-search.cgi?search=";
echo "$query';";
echo "</script>";
}

else {
echo "<script>";
echo "window.location = 'http://www.google.com/search?q=";
echo "$query';";
echo "</script>";
}

}
?>


test it here

Note that i only used javascript for the redirection because icouldnt use the Header (Location: URL) function in php. This is because i was submitting to the same page that the form was on.

If you're going to use this script in such a way that the form resides on another page, put the php code on the "search.php" page and the form on any pages you want your visitors to be able to search, then replace
CODE
echo "<script>";
echo "window.location = 'http://www.google.com/search?q=";
echo "$query';";
echo "</script>";


with
CODE
Header (Location: http://www.google.com/search?q=$query);


Do the same for the "search my journals" bit.

One snag with using javascript though is that when the user uses the back button after the search, they end up back on the search page... they'll have to quickly click "back" twice.

Also, you can modify the script to pop-up the external search while displaying the local search in the same window.

_ _ _
Girlie: No, you cant have more than one action statment. wherever it's implemented, i'm sure there's some behind the scenes work like i've done to pass variables around
Mr. Adams
Thanx faf it works fine...ty  :D
girlie
Maybe the Javascript solution I posted here for a similar idea could also be applied to this issue.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.