Solved

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

Posted on 2008-11-02
2
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

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…
Find out what you should include to make the best professional email signature for your organization.
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

695 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