Hi,
In my login page I’ve had a SELECT to get additional information during login. My code for that :
$("#password").parent().parent().append(
'<div style="margin-top:20px;" class="form-group"><label>Sélectionnez ... : </label><select id="an_scol" name="an_scol" class="form-control ewControl"></select></div>'
);
Now in my Server Events ->Global → Other → Login Page ->Page_load, I set my variables
if (!empty($_POST["an_scol"]))
{
SetClientVar("SelectedAn", $_POST['an_scol']);
}
But I got undefined when I try to call my variable client side. In Clients Scripts ->Global ->Pages with header/footer → Client Script :
var selectedAn = ew.vars.SelectedAn;
if(ew.vars.login.isLoggedIn){
$('<div id="myarea">' + selectedAn + '</div>).insertBefore($("#mycontent"));
}
What’s wrong with my code ?Help please.
mobhar
November 18, 2021, 12:08am
2
You may try to set the client variables in Page_Rendering server event, instead of Page_Load server event.
arbei
November 18, 2021, 1:22am
3
stpaulin wrote:
Now in my Server Events ->Global → Other → > Login Page > ->Page_load, I set my variables
if (!empty($_POST["an_scol"]))
{
SetClientVar("SelectedAn", $_POST['an_scol']);
}
>
Then the variable only exists in Login page.
Hi mobar
You may try to set the client variables in Page_Rendering server event, instead of Page_Load server event.
But I don’t have a Page_Rendering event for login page ???
Trying my code in Server Events->All pages->Page_rendering I got a “Undefined index” error for my $_POST[“an_scol”] variable.
My intention is to get the content of my select (an_scol), added in the login page, as a session variable and be able to access it later on the client side.
mobhar
November 18, 2021, 11:16am
5
Since Page_Rendering is for all pages, you will not find it under the Login page. You will see it from Server Events → Global → All Pages.
I managed to get a solution that works but I wonder if this is really the right way to do it ? ??In Sever Events->Global->All Pages->User_validated :
$_SESSION["SelectedAnId"] = $_POST["an_scol"];
And in Events->Global->All Pages->Page_Rendering :
if(isset($_SESSION["SelectedAn"])){
SetClientVar("SelectedAn", $_SESSION["SelectedAn"]);
}
I figure there must be a better way to do it.
mobhar
November 19, 2021, 12:31am
7
Your code seems fine and it resolves your case.