...

View Full Version : Converting two HTML forms into one



davide101
06-15-2006, 01:47 PM
I currently have a single, small search box in the top right corner of my site (like everyone should). I need to make this search box work with two different search scripts: Site Search and Forum Search.

It should look like this:

[Input Box] [Site Search Button] [Forum Search Button]

I am very comfortable with PHP but have yet to use it to pass variables between pages. Here's what I *think* I need to do to make this work:

1. User enters data into the search box and clicks the appropriate button
2. The value of the button clicked is passed to a script
3. The script examines the button pressed, determines which search script to use, and passes it the search term and hidden fields. I can (?) hardcode the required fields into the search script.

Is this the way to do it or am I off base? If yes, I'll definitely have a few follow-up questions so I can code it. Thanks!

David

P.S. The site in question is http://www.diabetesdaily.com. It's a noble cause and well worth your support. :)

davide101
06-15-2006, 01:48 PM
FYI, here are the two search forms that I'm trying to combine:



<!-- 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" />
<input type="submit" class="button" value="Go" /><br />
</form>

davide101
06-23-2006, 10:34 PM
Can anyone offer even the most basic framework of how this could work? I'm still stumped. Thanks!

fci
06-23-2006, 10:42 PM
play around with this and you will see what you need to do.

<?php
if (!empty($_POST)) {
print '<pre>'.print_r($_POST, true).'</pre>';
}
?>
<form method="post" action="">
<input size="15" name="search" value="search string" />
<input type="submit" value="Search1" name="search_name1">
<input type="submit" value="Search2" name="search_name2">
</form>

davide101
06-23-2006, 11:05 PM
Thanks for the advice, fci. In the twenty minutes after I posted it I was struck by an idea that's working well. Necessity is the mother of creation.

In case anyone else ever comes across this post, here's what I did:


<form method="post" action="<$MTCGIPath$><$MTSearchScript$>">
<fieldset>
<legend></legend>
<input type="hidden" name="Template" value="diabetes" />
<input type="hidden" name="IncludeBlogs" value="4" />
<input size="15" name="search" value="<$MTSearchString$>" />
<input type="hidden" name="do" value="process" />
<input type="hidden" name="showposts" value="0" />
<input type="hidden" name="query"/>
<input type="submit" value="Search Site" class="button">
<input type="submit" value="Search Forum" class="button" onclick="this.form.query.value=this.form.search.value; this.form.setAttribute('action','/forum/search.php');">
</fieldset>
</form>

I started by assuming the user was searchin the primary site but included the hidden fields for both scrips. If the user decides to search the forum, the onclick function switches to that script and loads the forum search field with the site search field's value.

fci
06-23-2006, 11:06 PM
umm, if you use my example, you don't need the onclick, just look at http://google.com.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum