Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Search Form Example

By: a guest on Mar 3rd, 2010  |  syntax: PHP  |  size: 1.40 KB  |  views: 267  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!-- search form where $q is GET passed by the search input field -->
  2.  
  3. <html>
  4. <head>
  5.  
  6. <!-- escape for title appearing in browser; handle Microsoft Smart Quotes document-wide -->
  7. <title><?php echo ($q) ? $q:'' ?> Example.com Search</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  9.  
  10. <!-- urlencode -->
  11. <link rel="canonical" href="http://example.com<?php echo ($q) ? '?q=' . $q:'' ?>" />
  12.  
  13. <!-- escape -->
  14. <meta name="description" content="Example.com Search: <?php echo ($q) ? $q:'' ?>" />
  15.  
  16. <!-- parsed keywords for "phrase one" "keyword1" "keyword2" with quotes, spaces pluses and minuses etc properly escaped -->
  17. <meta name="keywords" content="<?php echo ($phrasesCsv) ? $phrasesCsv:'' ?>" />
  18.  
  19. </head>
  20. <body>
  21.  
  22. <h1>Example.com Search: <?php echo ($q) ? $q:'' ?></h1>
  23.  
  24. <!-- escape for url and link of suggested term -->
  25. <?php if($suggestion) : ?>
  26.     <p>Did you mean to search for <a href="http://example.com/?q=<?php echo $suggestion?>"><?php echo $suggestion ?></a>?</p>
  27. <?php endif;?>
  28.  
  29. <form action="http://example.com/" method="GET" accept-charset="UTF-8"><!-- note accept-charset doesn't work properly in IE -->
  30. Search:
  31. <input type="text" name="q" value="<?php echo ($q) ? $q:'' ?>" />
  32. </form>
  33.  
  34. <!-- pagination, would be more complex in real life of course -->
  35. <a href="http://example.com/?q=<?php echo ($q) ? $q:'' ?>&page=<?php echo $page ?>">2</a>
  36.  
  37. </body>
  38. </html>