Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: "form" help.

  1. #1
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question "form" help.

    i never was great with forms mainly due to the fact that i have never before had anything but a free server (no Db, no php, no cgi) thats changed and i'd like to use some of these features in a form i'm having issue putting together the logic for it. a little help from you fine peeps would be great.

    this form will allow user to search different search engines from one place.

    so a seach box

    Code:

    search for:
    <input name="searchbox" type="text">


    then a list of seach engines that the user can select via radio button..

    Code:

    <p> google:
    <input type="radio" name="google" value="google's query URL=">
    </p>
    <p>hotbot:
    <input type="radio" name="hotbot" value="Hotbot's query URL=">


    the a simple submit button..

    i want the form to take the text from the "searchbox" and add it to the end of the value of the checked radio button then send the combined url to my targeted frame..

    seems so simple in theory..
    any help here would be great, thanks in advance.

    you can find my first post about this question http://www.ynot.com/index.php?name=P...=610842#610842

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Do you want a PHP solution or a javascript solution? The following is a PHP solution:

    Code:
    <?php
    if ($_POST['act'] == "do_search") { //if the action is do_search
       if ($_POST['q'] == "" || $_POST['se'] == "") { //if query or search engine is blank
            header('Refresh:3; url='.$_SERVER["PHP_SELF"]);
            echo 'You must enter a search query and select a search engine to search!';
       }
    
       else {
           if ($_POST['se'] == "google") {
    
    header('Location: http://www.google.com/search?hl=en&q='.$_POST["q"].'&btnG=Google+Search');
    
           }
    
            elseif ($_POST[''] == "hotbot") {
    
    header('Location: http://hotbot.com/?query='.$_POST["q"].'&ps=&loc=searchbox&tab=web&mode=search&currProv=ask          '); 
            }
    
             else {
                 header('Location: '.$_SERVER["PHP_SELF"]);
       }
          
    }
    
    else { //if form not submitted
    ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    <input type="hidden" name="act" value="do_search">
    
    Search: <input type="text" name="q" value=""><BR>
    <input type="radio" name="se" value="google">Google <input type="radio" name="se" value="hotbot"><BR>
    <input type="submit" value="Search">
    
    </form>
    
    <?php
    }
    ?>
    Added Later: If you want to make the search form on a seperate page, then have it target the specified frame, try the following:

    Code:
    <form action="filename.php" method="POST" target="framename">
    <input type="hidden" name="act" value="do_search">
    
    Search: <input type="text" name="q" value=""><BR>
    <input type="radio" name="se" value="google">Google <input type="radio" name="se" value="hotbot"><BR>
    <input type="submit" value="Search">
    
    </form>
    Where filename.php is the filename of the script above, and the framename is your target frame.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thanks~!

    thank you ~!

  4. #4
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default test

    ok i uploaded a test of the code you posted, and its loading the script but doing nothing..

    heres what i have it set up as..

    searchform.htm

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form action="search.php" method="POST" target="framename">
    <input type="hidden" name="act" value="do_search">
    
    Search: <input type="text" name="q" value=""><BR>
    <input type="radio" name="se" value="google">Google <input type="radio" name="se" value="hotbot">
      Hotbot<BR>
    <input type="submit" value="Search">
    
    </form>
    </body>
    </html>
    and search.php

    Code:
    <?php
    if ($_POST['act'] == "do_search") { //if the action is do_search
       if ($_POST['q'] == "" || $_POST['se'] == "") { //if query or search engine is blank
            header('Refresh:3; url='.$_SERVER["PHP_SELF"]);
            echo 'You must enter a search query and select a search engine to search!';
       }
    
       else {
           if ($_POST['se'] == "google") {
    
    header('Location: http://www.google.com/search?hl=en&q='.$_POST["q"].'&btnG=Google+Search');
    
           }
    
            elseif ($_POST[''] == "hotbot") {
    
    header('Location: http://hotbot.com/?query='.$_POST["q"].'&ps=&loc=searchbox&tab=web&mode=search&currProv=ask          '); 
            }
    
             else {
                 header('Location: '.$_SERVER["PHP_SELF"]);
       }
          
    }
    
    else { //if form not submitted
    ?>
    i dont claim to know anything about Php, so i already guess that my error is very noobler.

    you can see what happens here

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    invalid link It should be like this

    Edit.. it looks good though...

    You didn't specify a "framename"

    If you aren't using frames then remove that "target=" part.
    Last edited by BLiZZaRD; 02-01-2007 at 02:36 PM.
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  6. #6
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i will be using frames when i put it together for use, but for now, if it doesn't find the frame it will default back to _blank...

    but the search results aren't being displayed after search.php has run. the page remain blank.

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    OK...try the following:

    search.php
    Code:
    <?php
    if ($_POST['act'] == "do_search") { //if the action is do_search
       if ($_POST['q'] == "" || $_POST['se'] == "") { //if query or search engine is blank
            header('Refresh:3; url='.$_SERVER["PHP_SELF"]);
            echo 'You must enter a search query and select a search engine to search!';
       }
    
       else {
    
    header('Location: '.$_POST["se"].$_POST["q"]);
    
       }
          
    }
    
    else { //if form not submitted
    ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    <input type="hidden" name="act" value="do_search">
    
    Search: <input type="text" name="q" value=""><BR>
    <input type="radio" name="se" value=" http://www.google.com/search?hl=en&btnG=Google+Search&q=">Google <input type="radio" name="se" value="http://hotbot.com/?loc=searchbox&tab=web&mode=search&currProv=ask&query=">HotBot<BR>
    <input type="submit" value="Search">
    
    </form>
    
    <?php
    }
    ?>
    Standalone form:

    Code:
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    <input type="hidden" name="act" value="do_search">
    
    Search: <input type="text" name="q" value=""><BR>
    <input type="radio" name="se" value=" http://www.google.com/search?hl=en&btnG=Google+Search&q=">Google <input type="radio" name="se" value="http://hotbot.com/?loc=searchbox&tab=web&mode=search&currProv=ask&query=">HotBot<BR>
    <input type="submit" value="Search">
    
    </form>
    Tested and works.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    a search for "anything" with google checked, sends me to http://unknownerrors.net/search/&#37;3C?php%20echo%20$_SERVER['PHP_SELF'];?%3E

    hotbot is the same result.

    i just noticed the first post was leaving error_log,
    [01-Feb-2007 23:15:53] PHP Parse error: syntax error, unexpected T_ELSE in /home/unknowne/public_html/search/search.php on line 34
    Last edited by unknownerrors; 02-01-2007 at 07:19 PM.

  9. #9
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    another peice of info, i use firefox, i had the page with this form in it named searchform.htm, that was giving the above error.. i renamed it to searchform.php, now when i submit the form it reloads the page and hides the form.

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    try changing the file extension from html to php and see if that works. Also, are you calling the form from an html page with the action as search.php? I looked at your website from the link you posted and noticed that you need to change it to php as compared to html.

    Hope these help.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

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