Solved

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

Posted on 2008-11-02
2
426 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

839 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