Results 1 to 7 of 7
  1. #1
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Need help with basic form creation...
    Hey gurus - need your help, please.

    I need a "simple" search box. Example below:



    Here's what I need the "search" box to do:

    1) When a user enters a search term, ie: car parts, the searched for term appears to the right of "Results for" (like the highlighted area, but without the quotation marks around the searched for term).

    2) I need the searched for term to also become that page's title. Title tag would look something like <title><?=$SearchTerm?></title>

    3) The form will not be accessing any data and will not search any pages.

    4) Will be used on a php page.

    Clear as mud?

    Thanks for you help!


    ~ Denis
    Attached Images Attached Images
    Salty kisses, Sandy toes, and a Pirate's heart...

  2. #2
    Believe knight01's Avatar
    Join Date
    August 14th, 2006
    Location
    Dayton, Ohio
    Posts
    1,815
    Wouldn't a simple post form work for this?
    Something like:
    PHP Code:
     <form action="search.php" method="post">
            <
    input type="text" name="search" value="Search">
    <
    input type="submit" value="Search" name="search">
        </
    form
    Use
    PHP Code:
    $searchterm=$_REQUEST['search'
    to get the variable posted and use it as your title and to the right of 'results for'.
    Someday starts today
    Military Discounts

  3. #3
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Thumbs up
    Thank you, thank you, thank you!

    EXACTLY what I needed.

    ~ Denis
    Salty kisses, Sandy toes, and a Pirate's heart...

  4. #4
    Believe knight01's Avatar
    Join Date
    August 14th, 2006
    Location
    Dayton, Ohio
    Posts
    1,815
    I wrote that fast and have a couple errors.

    This code should work as a straight copy. It's not fancy but gets a base to work from.

    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="text" name="term" value="Search">
    <input type="submit" value="Search" name="search">
    </form>
    <?
    $searchterm=$_REQUEST['term'];
    ?>
    Results for <? echo $searchterm; ?><br>
    Someday starts today
    Military Discounts

  5. #5
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    I used your original one and it worked great!

    I'll try your revised version, too.

    Thanks, I really appreciate it.

    ~ Denis
    Salty kisses, Sandy toes, and a Pirate's heart...

  6. #6
    Full Member c4's Avatar
    Join Date
    January 18th, 2005
    Posts
    488
    I would strongly discourage using
    Code:
    $searchterm=$_REQUEST['term'];
    directly as this can lead to various security vulnerabilities (XSS attacks, SQL injections if you use a database, etc). The very least you should do to protect yourself (your website, server) is run any input through htmlspecialchars(), like this:
    Code:
    $searchterm=htmlspecialchars($_REQUEST['term']);
    For another example see http://myphpform.com/validating-forms.php
    [URL=http://www.hesk.com]Help desk software[/URL]

  7. #7
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Quote Originally Posted by c4
    I would strongly discourage using
    Code:
    $searchterm=$_REQUEST['term'];
    directly as this can lead to various security vulnerabilities (XSS attacks, SQL injections if you use a database, etc). The very least you should do to protect yourself (your website, server) is run any input through htmlspecialchars(), like this:
    Code:
    $searchterm=htmlspecialchars($_REQUEST['term']);
    For another example see http://myphpform.com/validating-forms.php
    Thanks for the heads up -

    I'm not using the search to access a database, directly. I've setup the page to recognize the title of the page (search term), that in turn triggers my contextual ad server showing only results for that search term.

    I went ahead and incorporated your input as well. Works great, too.

    Thanks to both of you, Knight01 and C4.

    ~ Denis
    Salty kisses, Sandy toes, and a Pirate's heart...

  8. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Folder Creation
    By is2aus in forum WebMerge (Fourthworld.com)
    Replies: 3
    Last Post: May 26th, 2009, 09:11 PM
  2. Creation
    By mobilebadboy in forum Virtual Family and Off-Topic
    Replies: 2
    Last Post: August 8th, 2007, 09:46 AM
  3. God's Creation
    By Spidey_ in forum Virtual Family and Off-Topic
    Replies: 3
    Last Post: June 28th, 2004, 02:08 PM
  4. creation of menu
    By tripa in forum Midnight Cafe'
    Replies: 1
    Last Post: February 19th, 2002, 11:51 PM

Posting Permissions

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