URL Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anilmist
Forum Newbie
Posts: 2
Joined: Fri Dec 06, 2013 4:48 am

URL Problem

Post by anilmist »

Hi
1.
I have a website , and at the top of the page, there is a dropdown list to let the users specify either English and Spanish as a language.

This works fine if the language is the first selection made on the webpage, and the URL changes to http://www.mywebsite...dex.php?lang=es if Spanish..as it should.

However, if I perform a search further down the page using either free text entry, or by any of the other dropdown boxes, then the language part of the URL is not recognized.

So, instead of a search result ending up as

mywebsite.es/index.php?lang=es/search.php?location=&type1=&price1=&condition=&category=&q=shoes
I get
mywebsite.es/search.php?location=&type1=&price1=&condition=&category=&q=shoes

Here are snippets of the script I have at the moment:

Code: Select all

<script type="text/javascript">
function go(){
location=document.lan.langu.
options[document.lan.langu.selectedIndex].value
}
</script>
 
          <form name="lan">
          <select name="langu" size="1" onChange="go()">
              <option><?php print translate("Language"); ?></option>
              <option value="">English</option>
              <option value="/index.php?lang=es">Espa&#xF1;ol</option>
          </select>
          </form>

<form name='search' action='<?php print $config_baseHREF ?>search.php'>
(the search.php files calls up the rest of the URL after the language).

2.
Also, if the language is changed half way through a session, is there a way to change the language of the page, so that the existing content on the webpage remains, and does not go back to the home page.

Thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: URL Problem

Post by Celauran »

You have the language setting tied to index.php, that's the problem. index.php?lang=es/search.php?location=foo&price=bar etc isn't ever going to happen. You can have your language selector fire an AJAX request on change, which will reload the page in the desired language, or you can append the language setting to your existing query string and have the language change on next page load.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: URL Problem

Post by pickle »

You should store your language in a cookie or session - then it isn't dependant on the current query string.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply