Solved

Give User Option of Submitting to Two Different Search Scripts

Posted on 2006-06-14
12
211 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 250 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 250 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now