Forums

redirect to current page

Canard 28 Oct, 2014
Hi !
I created a form that is displayed on top of the pages site wide. It shows two buttons to switch between french and english. The site owners want very specific parts to be translated and different layouts depending on the selected language. What my form does is simply store the selected language in a session variable. Well, the form works like a charm, the only remaining problem is that I would like to redirect to the currently viewed page after submit (so the user just change the language and the current page gets reloaded in the selected language theme). If I leave redirect URL blank, I get a blank content, the same if I try to put a #. I tried the following in form code :
<?php
$currenturl = JURI::current();
$form->data['redirect_url'] = $currenturl;
?>

hopping that would override the form URLs setting but in vain.
Any idea ?
Canard 30 Oct, 2014
Sorry Calculus but tit is not the answer I was expecting😉
GreyHead 30 Oct, 2014
Hi Canard,

I don't' think that CFv45 let you set a variable redirect URL like that (You could do it in CFv4). Please try using the Joomla! redirection code in a Custom Code action instead
<?php
$app = JFactory::getApplication();
$app->redirect(JURI::current());
?>
or, if that doesn't work this variant might
<?php
$app = JFactory::getApplication();
$url = JURI::current();
$app->redirect($url->toString());
?>

Bob
Canard 30 Oct, 2014
Thank you Bob, I tried what you suggested, but it didn't work, the browser's message explains there are too many redirections, error code (in Chrome) : ERR_TOO_MANY_REDIRECTS.

If helpful, here's what var_dump($app) gives me :
object(jsite)(7) { ["_errors"]=> array(0) { } ["_clientId"]=> int(0) ["_messageQueue"]=> array(0) { } ["_name"]=> string(4) "site" ["scope"]=> string(17) "mod_chronocontact" ["requestTime"]=> string(16) "2014-10-30 12:05" ["setTemplate"]=> string(19) "Cybelle_planete_new" } 

and var_dump($url) :
string(55) "http://www.cybelle-planete.org/ecovolontariat/index.php" 
Canard 30 Oct, 2014
Edit : I have V3.1 and can't find what you call a custom code action, so I tried in form code itself
<?php

if(isset($_POST[lang]))
{
$app = JFactory::getApplication();
$url=JURI::current();
$app->redirect($url);
}

?>
Max_admin 30 Oct, 2014
Hi Canard,

Please try your code in the "on submit after email" code box!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Canard 30 Oct, 2014
Hi Max, I did try with no luck.

here's my form's code
<form id="ChronoContact_langue" action="index.php?option=com_chronocontact&task=send&chronoformname=langue" method="post" name="ChronoContact_langue">
<table class="langTable">
<tbody>
<tr>
<td>

<BUTTON class="langButton" name="lang" value="fr" type="submit" title="Français">
    <IMG src="templates/Cybelle_planete_new/images/fr.png" alt="fr"></BUTTON>
</td>
<td>

<BUTTON class="langButton" name="lang" value="uk" type="submit" title="English">
    <IMG src="templates/Cybelle_planete_new/images/uk.png" alt="uk"></BUTTON>
</td>
</tr>
</tbody>
</table>
</form>


on submit code (after sending email)
<?php
/*store language in session variable*/
$_SESSION[language]=$_POST[lang];

/*redirect to current page*/
$app = JFactory::getApplication();
$url=JURI::current();
$app->redirect($url);

?>


In the form URLs tab no values are set
Am I trying to do something weird ? I mean as my form is on every page, I have to allow users to switch language without being always redirected to front.
Thanks again for the nice support !
Regards
David.
Max_admin 30 Oct, 2014
Hi David,

You have J1.5 and I'm not sure if JURI or JFactory work in this version, please try to debug the $url variable using print_r

You may also try to find a language plugin/module which does what you need ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Canard 30 Oct, 2014
Answer
Thanks Max
you helped me realize $url was correct in form code but not in after email custom code, so here's what I finally did :
I created a hidden field in form to post the current URL and applied redirect in custom code.
form :
<?php
/*get current URL*/
$url=JURI::current();

?>
<form id="ChronoContact_langue" action="index.php?option=com_chronocontact&task=send&chronoformname=langue" method="post" name="ChronoContact_langue">
<table class="langTable">
<tbody>
<tr>
<td>

<BUTTON class="langButton" name="lang" value="fr" type="submit" title="Français">
    <IMG src="templates/Cybelle_planete_new/images/fr.png" alt="fr"></BUTTON>
</td>
<td>

<BUTTON class="langButton" name="lang" value="uk" type="submit" title="English">
    <IMG src="templates/Cybelle_planete_new/images/uk.png" alt="uk"></BUTTON>
<input type="hidden" name="currenturl" value="<?php echo $url ?>">
</td>
</tr>
</tbody>
</table>
</form>


On Submit code - after sending email:
<?php
/*store language in session variable*/
$_SESSION[language]=$_POST[lang];

/*redirect to current page*/
$url=$_POST[currenturl];
$app = JFactory::getApplication();
$app->redirect($url);

?>

So it is working as expected, except when I display a chronoconnectivity content which url is:
index.php?option=com_chronoconnectivity&connectionname=detailprojet&Itemid=59

(in this case I get back to front page)
For I have a search form linked to a chronoconnectivity content (which url is unluckily not rewritten by Joomla's SEF), you can have a look at it http://www.cybelle-planete.org/ecovolontariat/.
But this is another issue.
Thank you for guiding me to the right direction.
David
This topic is locked and no more replies can be posted.