Help With Search Box/form

liunx

Guest
Hi i am trying to create a search box><!--/coloro-->www.mysite.co.uk/shop/compareprices/searchterm.htm<!--colorc--></span><!--/colorc--><br />"searchterm" being the variable submitted in the search box<br /><br />At present i have the following search box/form:<br /><!--coloro:#0000FF--><span style="color:#0000FF"><!--/coloro--><form style="margin-bottom:0;" action="http://www.mysite.co.uk/shop/index.php" method="get"><br /><input name="ps" type="text" value="Enter Keywords"><!--/coloro-->http://www.mysite.co.uk/shop/index.php?ps=searchterm&sv=1<!--colorc--></span><!--/colorc--><br /><br />I have already got the mod rewrite working all i need is a searchbox/form which will take you to <!--coloro:#FF0000--><span style="color:#FF0000"><!--/coloro-->www.mysite.co.uk/shop/compareprices/searchterm.htm<!--colorc--></span><!--/colorc--> when submitted.<br /><br />is it possible to do this?<br /><br />Any help appreciated.<br /><br />William<br /><!--content-->
Yes... Changing the URL of the form's action property should do the trick.<br />I'm not sure that I quite get what you're asking for though.<br /><br />What's your mod rewrite line for the URL?<!--content-->
<!--quoteo(post=12044:date=Oct 3 2007, 05:25 PM:name=Thomas Thomassen)--><div class='quotetop'>QUOTE(Thomas Thomassen @ Oct 3 2007, 05:25 PM) <img src='http://www.webdesignerforum.co.uk/style_images/1/post_snapback.gif' alt='*' border='0' /></div><div class='quotemain'><!--quotec-->Yes... Changing the URL of the form's action property should do the trick.<br />I'm not sure that I quite get what you're asking for though.<br /><br />What's your mod rewrite line for the URL?<!--QuoteEnd--></div><!--QuoteEEnd--><br />Hi Thomas <br /><br />What i want is for the form action to take you to for example:<br />www.mysite.co.uk/shop/compareprices/widget.htm <br />(with "widget" being the term submited in the search form)<br />So what i need is the code for the form which will do this.<br /><br />I probably confused things mentioning the mod rewrite, the search form is what i need to get working.<br /><br />Sorry if i am not very clear i am still somewhat of a beginner.<br /><br />William<!--content-->
Ok<br /><br />With mod rewrite you can make<br />http://www.mysite.co.uk/shop/index.php?ps=searchterm<br />redirects to by using the at the end of your rewrite rule [R]<br />www.mysite.co.uk/shop/compareprices/searchterm.htm<br /><br />so your form's action is <!-- m --><a class="postlink" href="http://www.mysite.co.uk/shop/index.php?ps=searchterm">http://www.mysite.co.uk/shop/index.php?ps=searchterm</a><!-- m -->, and when a user submit a search the server automaticly redirects to your new URL.<!--content-->
I believe it might look something like this:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteRule ^/?index.php?ps=(.*)$ compareprices/$1\.html [L]<!--c2--></div><!--ec2--><br /><br />or perhaps:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteRule ^/?index.php\?ps\=(.*)$ \/compareprices\/$1\.html [L]<!--c2--></div><!--ec2--><br /><br />try both, see what happens<!--content-->
<!--quoteo(post=12061:date=Oct 3 2007, 09:04 PM:name=php_penguin)--><div class='quotetop'>QUOTE(php_penguin @ Oct 3 2007, 09:04 PM) <img src='http://www.webdesignerforum.co.uk/style_images/1/post_snapback.gif' alt='*' border='0' /></div><div class='quotemain'><!--quotec-->I believe it might look something like this:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteRule ^/?index.php?ps=(.*)$ compareprices/$1\.html [L]<!--c2--></div><!--ec2--><br /><br />or perhaps:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteRule ^/?index.php\?ps\=(.*)$ \/compareprices\/$1\.html [L]<!--c2--></div><!--ec2--><br /><br />try both, see what happens<!--QuoteEnd--></div><!--QuoteEEnd--><br />I already have the mod rewrite working ok.<br /><br />RewriteRule ^compareprices/([^/]+)\.htm$ index.php?ps=$1&sv=1 [L]<br /><br />The problem i have is when you enter a search term for example "widget" this sends you to<br />www.mysite.co.uk/shop/index.php?ps=widget&sv=1"<br /><br />As i have got the rewriterule in place i want the search box form to send you to <!-- w --><a class="postlink" href="http://www.mysite.co.uk/shop/compareprices/widget.htm">www.mysite.co.uk/shop/compareprices/widget.htm</a><!-- w --> <br /><br />I need the code for the form which will do that.<br /><br />William<!--content-->
Oh I see... here is a bit of code:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><script type="text/javascript"><br />var formid = "theformid";<br />var submitid = "submitbuttonid";<br />function updateform() {<br />   var valoo = document.getElementById(submitid).value;<br />   document.getElementById(formid).action='http://www.mysite.co.uk/shop/compareprices/'+valoo+'.htm'<br />}<br /></script><!--c2--></div><!--ec2--><br /><br />to make this work, replace "theformid" with the ID of your form (give it><img src='http://www.webdesignerforum.co.uk/style_images/1/post_snapback.gif' alt='*' border='0' /></div><div class='quotemain'><!--quotec-->I already have the mod rewrite working ok.<br /><br />RewriteRule ^compareprices/([^/]+)\.htm$ index.php?ps=$1&sv=1 [L]<br /><br />The problem i have is when you enter a search term for example "widget" this sends you to<br />www.mysite.co.uk/shop/index.php?ps=widget&sv=1"<br /><br />As i have got the rewriterule in place i want the search box form to send you to <!-- w --><a class="postlink" href="http://www.mysite.co.uk/shop/compareprices/widget.htm">www.mysite.co.uk/shop/compareprices/widget.htm</a><!-- w --> <br /><br />I need the code for the form which will do that.<br /><br />William<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteRule ^compareprices/([^/]+)\.htm$ index.php?ps=$1&sv=1 [R]<!--c2--></div><!--ec2--><br />With the R flag you server should redirect you to the URL you want with no extra code in the form or any javascript.<!--content-->
<!--quoteo(post=12063:date=Oct 3 2007, 09:30 PM:name=php_penguin)--><div class='quotetop'>QUOTE(php_penguin @ Oct 3 2007, 09:30 PM) <img src='http://www.webdesignerforum.co.uk/style_images/1/post_snapback.gif' alt='*' border='0' /></div><div class='quotemain'><!--quotec-->Oh I see... here is a bit of code:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><script type="text/javascript"><br />var formid = "theformid";<br />var submitid = "submitbuttonid";<br />function updateform() {<br />   var valoo = document.getElementById(submitid).value;<br />   document.getElementById(formid).action='http://www.mysite.co.uk/shop/compareprices/'+valoo+'.htm'<br />}<br /></script><!--c2--></div><!--ec2--><br /><br />to make this work, replace "theformid" with the ID of your form (give it><img src='http://www.webdesignerforum.co.uk/style_images/1/post_snapback.gif' alt='*' border='0' /></div><div class='quotemain'><!--quotec-->do a string replace in the JS:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function jumpit(keyword) {<br />document.location="http://www.mysite.co.uk/compareprices/" + keyword.replace(/ /,"-") + ".htm";<br />}<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd--><br />Thanks again php_penguin that works fine.<br /><br />Very much appreciated.<br /><br />William<!--content-->
 
Back
Top