Thread: URL Problem

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    URL Problem


    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 mywebsite.com/index.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:

    <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
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    do you seriously want to have the URL

    Code:
    mywebsite.es/index.php?lang=es/search.php?location=&type1=&price1=&condition=&category=&q=shoes
    Why?? That URL makes no sense to me whatsoever. What I would expect is something like this:

    Code:
    mywebsite.es/search.php?lang=es&location=&type1=&price1=&condition=&category=&q=shoes
    Either way, as long as you don't include the language selection as a form field or in the target URL, you're not gonna see the language in the URL.



    Originally Posted by anilmist
    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.
    What do you mean by "change the language of the page"? Update the URL? Translate the content?



    // Also, [ PHP ] tags, please. There's a thread saying

    Please wrap PHP codes using the tag <-- READ THIS BEFORE POSTING

    right on top of this forum.
    Last edited by Jacques1; December 6th, 2013 at 06:27 AM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0
    Thanks Jacques, and please bear with me, as I am not a seasoned programmer.
    I have no specific preference as to where the language part should be placed in the URL, so if I understand you correctly, all I do is place the language selection dropdown inside the form.

    Regarding the language of the page, I have a few other dropdown lists in the form. If someone selects items from any of these dropdowns, and then changes the language, then I was looking to keep these selections, but in the new language.


    Originally Posted by Jacques1
    Hi,

    do you seriously want to have the URL

    Code:
    mywebsite.es/index.php?lang=es/search.php?location=&type1=&price1=&condition=&category=&q=shoes
    Why?? That URL makes no sense to me whatsoever. What I would expect is something like this:

    Code:
    mywebsite.es/search.php?lang=es&location=&type1=&price1=&condition=&category=&q=shoes
    Either way, as long as you don't include the language selection as a form field or in the target URL, you're not gonna see the language in the URL.





    What do you mean by "change the language of the page"? Update the URL? Translate the content?



    // Also, [ PHP ] tags, please. There's a thread saying

    Please wrap PHP codes using the tag <-- READ THIS BEFORE POSTING

    right on top of this forum.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Please don't full-quote my replies. They're right above your post, so no need to repeat them.

    Originally Posted by anilmist
    I have no specific preference as to where the language part should be placed in the URL, so if I understand you correctly, all I do is place the language selection dropdown inside the form.
    That would be the easiest solution. If this breaks your layout or if the language selection is totally misplaced in the form, you could also use a hidden field or append the language parameter to the form target.



    Originally Posted by anilmist
    Regarding the language of the page, I have a few other dropdown lists in the form. If someone selects items from any of these dropdowns, and then changes the language, then I was looking to keep these selections, but in the new language.
    Store the current selections in the session or a cookie. If the user visits the page with preset selections, you restore them and then delete the values from the session or cookie.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo