• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Give User Option of Submitting to Two Different Search Scripts

Good afternoon,

I want to have one input box and give the user two buttons: "Search Site" or "Search Forum". Currently I have these two forms:

SITE SEARCH:
<form method="post" action="/mt/mt-search.cgi">
<fieldset>
<legend></legend>
<input type="hidden" name="Template" value="diabetes" />
<input type="hidden" name="IncludeBlogs" value="4" />
<input size="15" name="search" value="" />
<input type="submit" value="Search" class="button">
</fieldset>
</form>

FORUM SEARCH:
<form action="/forum/search.php" method="post">
<input type="hidden" name="do" value="process" />
<input type="hidden" name="showposts" value="0" />
<input type="text" class="bginput" name="query" size="20" /><!-- go button -->
<input type="submit" class="button" value="Go" /><br />
</form>

How would I put these two forms into one?
0
EdelmanPlumbing
Asked:
EdelmanPlumbing
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
Eddie ShipmanAll-around developerCommented:
You can submit the correct form via javascript using only one submit button. You must also have some way
for the user to designate which way to post, such as a radio button.  Then, depending on which radio
button was checked post the form that is needing to be posted.
0
 
EdelmanPlumbingAuthor Commented:
Is there a way to do it with two separate buttons?

Also, each search script is expecting a differently named search string. Is there a way to rename the input after the press of a button? I'm out of my element here, so I'd appreciate any guidance on where to look for more information. What functions are important here?

Thanks for your help.
0
 
Eddie ShipmanAll-around developerCommented:
Well, DUH, the button in each form submits the form it is contained in so the Search button
would submit the data to /mt/mt-search.cgi and the Go button would submit the data in its
form to /forum/search.php.

It looks like you have everything setup to work correctly just as it is, there is no need to rename anything.

Think of a form as a container, too. It will submit all input elements contained in it when it is submitted.
The SITE SEARCH form will submit only these fields:
<input type="hidden" name="Template" value="diabetes" />
<input type="hidden" name="IncludeBlogs" value="4" />
<input size="15" name="search" value="" />

and the FORUM SEARCH form will submit only these fields:
<input type="hidden" name="do" value="process" />
<input type="hidden" name="showposts" value="0" />
<input type="text" class="bginput" name="query" size="20" />

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GrandSchtroumpfCommented:
you could do some client-side manipulations using javascript, but then your search would not work when javascript is disabled or not available.
using 2 different forms is much better.
another solution is to submit to a third page that can handle both the site search and the forum search...  but you'll need to code that page.
0
 
EdelmanPlumbingAuthor Commented:
GrandSchtroumpf,

About 3% of my users (some regulars) don't use javascript so it's important to me. My site is frequented by a lot of computer illiterate people so I'm trying to keep it super simple.

Without Javascript, is the following possible?

1. User enters search term and hits Site Search or Forum Search.
2. Search term is sent to a second page that evaluates the information and passes it on to the right script.

If you can offer a theoretical framework, I'm happy to research the functions and make it work. Right now I'm wandering in the dark. I do a lot of PHP coding within pages but very little passing info between them.

0
 
Eddie ShipmanAll-around developerCommented:
As I said before, if you write one script to handle both searches, you will need to differentiate
between the two in order to know where to send the posted data, and your users will need
to have either:
1. a radio button for forum search or site search
2. a different form and submit button for each search

It is much simpler to have the two forms then you don't have to worry about messing around
with what was passed.
0
 
GrandSchtroumpfCommented:
EddieShipman, if you have 2 submit buttons on one single form the value of the button you clicked is submited while the other is not.  So, your server side can determine which of the buttons was clicked.

> Without Javascript, is the following possible?

Yes it is possible...
The easiest is for the server-side to check which button was clicked and redirect to the corresponding page...
If I remember correctly, there are 2 redirection codes one that will work and the other one that won't.
I think the one that works is "HTTP/1.1 307 Temporary Redirect".
0
 
CWS (haripriya)Commented:
You can put both the forms in same page.

Give 2 submit buttons with one form action. In your next page, check which submit button is seleted and give a if condition, accordingly display any of the 2 forms.

0
 
Eddie ShipmanAll-around developerCommented:
Yes, I forgot about that one. As long as it goes to a script to determine which one to forward
the postdata to.
0
 
GrandSchtroumpfCommented:
Note that the best solution is not to use an HTTP redirection and handle the search directly inside the page that the form submits to.
Something like this:

<?
  if (isset($_POST['forum_search'])) {
    include "forum/search.php";
  }
  else {
    /* call your cgi */
  }
?>

I don't know how you call the cgi from php, but i'm confident there is a method that allows you to do that.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now