Solved

Creating a search field that will search our website and produce results

Posted on 2014-01-13
11
225 Views
Last Modified: 2014-01-22
I have created a search field for our website and when I test it, it just goes back to the home page.  Here is the code:

<form action="http://www.companysite.com" method="post" class="search-form">
    	<label for="search">Search</label>
    	<input type="search" placeholder="Search" title="Search" class="q" name="search" id="search">
    	<input type="submit" class="submit" value="Go" name="submit">
</form>

Open in new window


What am I doing wrong?

Thanks,
John
0
Comment
Question by:jebolton
  • 5
  • 4
  • 2
11 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39778210
Either you need to use some type of server side code that will search your database or an index OR you are using https://developers.google.com/custom-search/ or I keep forgetting about bing http://www.bing.com/blogs/site_blogs/b/developer/archive/2010/03/22/add-a-bing-search-box-to-your-site-in-3-easy-steps.aspx
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39780264
it's going back to the homepage because your action attribute in your form tag is set to your home page. how exactly are ypu producing the results?
0
 

Author Comment

by:jebolton
ID: 39780816
I got it through a tutorial.  I'm thinking I need a cgi script or a javascript to fix this problem.

I looked into the google and bing custom search and I'm wondering if there is a free (ad free) script out there that would do the job.  My deadline prevents me from learning the code and creating my own version at this point.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39780942
If you don't mind going to another tab to google there is always

 <form action="https://google.com/search" method="get" target="_blank">
    Search me<br>
    <input name="q"><br>
    <button type="submit">Search</button>
    
  </form>

Open in new window


Or use serverside code to direct to

https://www.google.com/search?q=site:yourdomaine.com+search_term
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39780951
post the link to the tutorial and maybe we can figure out how it works
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:jebolton
ID: 39781058
Scott,
  So would I put the "server side" code mentioned above after the action statement in parentheses?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39781115
>So would I put the "server side" code mentioned above after the action statement in parentheses?

I meant use php/asp and process but you could just use javascript.

http://jsbin.com/aquWEDa/2/edit

<!DOCTYPE html>
<html>
<head>

<meta charset=utf-8 />
 
<script>
function searchMe(){
	var myTextField = document.getElementById('myText');
	if(myTextField.value != "")
		window.open("https://www.google.com/search?q=site:yourdomaine.com+" + myTextField.value)
	else
		alert("Please enter a search term")		
}
</script>
<title>JS Bin</title>
</head>
<body>
<input type='text' id='myText' />
<input type='button' onclick='searchMe()' value='Search' />

</body>
</html>

Open in new window

0
 

Author Comment

by:jebolton
ID: 39786777
I have decided to go the Google custom search route.  I have it working on the site but I need to customize it to fit the are I want to put it.
0
 

Author Comment

by:jebolton
ID: 39799945
What I ended up doing was to purchase the Google site search.  Working with the support specialist and the ability to remove ads, it was well worth the purchase.  The search feature is up and running in the design and format that I wanted.  Thanks for the insights and suggestions.
0
 

Author Closing Comment

by:jebolton
ID: 39799953
Thanks for your help Scott.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39799967
I think that was the best choice to use custom search! and pay!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now