Solved

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

Posted on 2008-11-02
2
422 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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.

762 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

18 Experts available now in Live!

Get 1:1 Help Now