Solved

Give User Option of Submitting to Two Different Search Scripts

Posted on 2006-06-14
12
236 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Objects on Same Line 2 30
HTML &#0153 2 17
Can't find PHP files on account that has WordPress 3 27
Create CSS Animation for Page Transitions 4 26
Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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