Welcome Guest, Not a member yet? Register   Sign In
Fixing URL after language selection from dropdown menu
#1

[eluser]thekrow[/eluser]
Hello, trying my best to be clear, so sorry for the length.

I have a dropdown menu which submits a selected language by the user. The "action" attribute takes the submission to my default controller in which then I retrieve the submitted option via $_POST.

Based on the submitted option, e.g. 'sp' for Spanish, I call a function which fixes my URL so that in the end it looks like http://mysite.com/sp/about-us and not http://www.mysite.com/about-us.

Here's the issue:
I don't know how to fix my url after that one submission, basically because the URL submitted (the one contained in "action") is placed in my address bar without being fixed. Not what I want! as my goal is to fix it first and then place it in the address bar, but then again, to do that I need to go first through the function in my controller.

Here's a flow description:
1. User selects language
2. Form containing URL to my default controller is submitted
3. Address bar updates the URL coming from the "action" attribute.
4. index() is called and within it, fix_uri() inserts 'sp' in my new URL
5. $url is passed to $this->smarty->assign('url', $url)
6. Wait for next call.

Note: as you can see I'm using Smarty.

In the end I'm left with a URL that was fixed but it's NOT updated in my address bar, it was simply assigned to be called next time. So basically what happens is, next time the user selects a language from the dropdown menu then the address bar UPDATES the URL entered in the previous call, 'sp' in my example.

***sigh***

Any suggestions, recommendations will be very very much appreciated. I've spent 1 1/2 days trying to solve this issue to no avail. CI routing hasn't helped me for some reason, same situation with JavaScript. I just haven't been able to get what I need.

Note 2: my default controller has a $default_url for the first time the user accesses my website. If the user selects a different language, an IF/ELSE statement is executed so that the user's choice is performed instead of the $default_url.

Note 3: because of Smarty, I cannot use any CI functions in my view files. Just in case Smile

Thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB