Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Converting two HTML forms into one

    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.

  • #2
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    FYI, here are the two search forms that I'm trying to combine:

    Code:
    <!-- 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>

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can anyone offer even the most basic framework of how this could work? I'm still stumped. Thanks!

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    play around with this and you will see what you need to do.
    PHP Code:
    <?php
    if (!empty($_POST)) {
        print 
    '<pre>'.print_r($_POSTtrue).'</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>

  • #5
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    			 <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.

  • #6
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    umm, if you use my example, you don't need the onclick, just look at http://google.com.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •