Solved

Send search query in URL, eg. ...search.php?query=blah

Posted on 2008-11-02
2
425 Views
Last Modified: 2012-08-13
Hi,

I'm currently using the attached code to search a certain page depending on the dropdown chosen, at present, the code sends the user to the search results page with the query hidden from the url. His it possible for someone to modify this code so that the search term is shown in the URL?

EG.

The user searches for "test", so the url they are returned to would be "search.php?q=test".

Note: The javascript below sets the url they are returned to depending on what dropdown box is chosen.

Thanks,
Paul
<script type="text/javascript"><!--
function setAction(theForm){
  theForm.action = theForm.evt.value+theForm.trigger.value+".php";
}
--></script>
 
<form name='search' id='theSearchForm' method='post' onSubmit='setAction(this)' >
<input type='hidden' name='trigger' value='search_caws' >
<input type='text' name='search' size=25 maxlength=25 >
<select name='evt'>
<option value='http://cawsearch.com/impact/'>TNA iMPACT</option>
<option value='http://cawsearch.com/svr2008/'>Smackdown vs RAW 2008</option>
<option value='http://cawsearch.com/firepro/'>Fire Pro Wrestling Returns</option>
<option value='http://cawsearch.com/dor2/'>Day Of Reckoning 2</option>
<option value='http://cawsearch.com/wm21/'>WrestleMania 21</option>
</select>
<input type='Submit' name='search_caws' value='CAWSearch' onClick='this.form.trigger.value=this.name;' >
<input type='Submit' name='lucky' value='I&#39m Feeling Lucky' onClick='this.form.trigger.value=this.name;' >
</form>

Open in new window

0
Comment
Question by:m0tSiE
2 Comments
 
LVL 13

Accepted Solution

by:
AielloJ earned 500 total points
ID: 22862336
You can change your form to the GET method by adding the "action" property to the URL and the php code to echo the search text (which I'm assuming is in the text field named 'search'.  I have a question as to why you are changing something that is working?  GET methods of posting reveal how your website is able to be controlled whereas a POST method does not.  A user can create their own URL's in the browser and possibly bypass your form code and any checking it may be doing.

<form name='search' action="search.php?q=<?php echo this.search; ?>" method="get"  id='theSearchForm">
0
 

Author Closing Comment

by:m0tSiE
ID: 31512459
Cheers :D
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

813 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

17 Experts available now in Live!

Get 1:1 Help Now