Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Give User Option of Submitting to Two Different Search Scripts

Posted on 2006-06-14
12
Medium Priority
?
284 Views
Last Modified: 2010-04-09
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
Comment
Question by:EdelmanPlumbing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16905822
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
 

Author Comment

by:EdelmanPlumbing
ID: 16906381
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16906455
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
Industry Leaders: 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!

 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16906777
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
 

Author Comment

by:EdelmanPlumbing
ID: 16907041
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16907153
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
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16907301
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
 
LVL 16

Accepted Solution

by:
CWS (haripriya) earned 1000 total points
ID: 16909909
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 16911260
Yes, I forgot about that one. As long as it goes to a script to determine which one to forward
the postdata to.
0
 
LVL 30

Assisted Solution

by:GrandSchtroumpf
GrandSchtroumpf earned 1000 total points
ID: 16912841
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question