OliverWi wrote: ↑Sat Nov 02, 2019 8:10 am
Hello Amos,
is it possible to change the dynaform setting to a different language using a trigger before I open the dynaform?
Or can this be done with Javascript when the form is already open?
Thank you for your help.
Kind Regards
Oliver
Hi, I don't know why but your post really interested me so I tried to make it work in our environment and I'm 99% sure that it works with this trigger before each dynaform that you need to change the language programatically. Feel free to modify it however you want but I think that the way I did it, it's easier to use it everywhere. The basics are there :
Code: Select allfunction getStringBetween($str,$from,$to)
{
$sub = substr($str, strpos($str,$from)+strlen($from),strlen($str));
return substr($sub,0,strpos($sub,$to));
}
$actual_url = "$_SERVER[REQUEST_URI]"; //get current url without the server
$dynUID = $_GET['UID']; //get the dynaform unique ID
$query = "SELECT DYN_CONTENT FROM DYNAFORM WHERE DYN_UID='$dynUID'";
@@query = $query;
$result = executeQuery($query);
if(!empty($result) && count($result) > 0)
{
$dynContent = array();
$dynContent = $result[1]['DYN_CONTENT'];
$dynContent = json_decode($dynContent,true);
$dynLanguage = $dynContent['items'][0]['language'];
@@dynLanguage = $dynLanguage; //defaut language of the dynaform
}
$actual_url = str_replace("/sysworkflow","",$actual_url); //remove the sysworkflow from the url
@@actual_url = $actual_url;
$from = "/";
$to = "/";
$currentLanguage = getStringBetween($actual_url,$from,$to); //get the current language that was chosen by the user when logging on
@@currentLanguage = $currentLanguage;
if($currentLanguage != $dynLanguage) //only redirects if the language of the dynaform is different than the current language
{
$old = $from . $currentLanguage . $to;
$new = $from . $dynLanguage . $to;
$new_url = str_replace($old,$new,"$_SERVER[REQUEST_URI]");
header("Location: $new_url"); //so in the end, it changes the language in the url because when you load a dynaform it uses this to set the language
}