Solved

Give User Option of Submitting to Two Different Search Scripts

Posted on 2006-06-14
12
271 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
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!

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

690 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