This topic is locked

How to set a session variable in a before display event

11/11/2007 11:38:06 PM
PHPRunner General questions
G
giles author

Hi,

I'm trying to call a php function with a session variable from a beforedisplay event on an Add record page:
global $strTableName, $conn;

setpricesetid($_SESSION[$strTableName."_masterkey1"]);

Trouble is I don't get any value in the session variable.
I inserted the following lines between the global declaration and the function call to write a footprint to a "results" table and it confirmed the session variable was blank or null.
$strSQLInsert = "insert into results (ResultName, ResultValue) values ('Session var=','".$_SESSION[$strTableName."_masterkey1"]."')";

db_exec($strSQLInsert,$conn);

Before inserting the function call the Add page was indeed adding the record correctly linked to its master table.
what am I doing wrong here? Is that session variable not set up at the time of the beforedisplay event?
Giles

Admin 11/12/2007

Hi,
your code looks correct.

Please note that the sessions variable is filled only when you click on details link on Master list page.

If you get to Details table using Quickjump control the sessions variable is empty.

G
giles author 11/12/2007

Hi Alexey,

Thanks, i see where the issue is now... I need to set the session variable at a different stage.
So...how do I get hold of the id of the record I'm currently displaying in the edit page in a beforedisplay event on that page? (This is kind of like the reverse of using smarty to set displayed values....)
$_SESSION["myrecordid"]= ???
It'll probably be obvious but I just cannot think what it is. Note that I don't display the id in the list of fields being edited although it is available in the Edit Record[ ] table title.
Thanks in advance,
Giles

G
giles author 11/12/2007

Ok,

That was a dumb question on my behalf...been working too hard on this project...
Of course the answer is:
global $data;
$_SESSION["myrecordid"] = $data["id"];
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23278&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />
Now here's the real question...
That session variable allows me to look up another id field in a different table via a function. I'm also storing that id in a session variable.
I need to pass that second session variable as a parameter to a javascript...
Ok, just worked out how to do that after reviewing an earlier thread where some-one told me how...
Can use an event or a code snippet.
echo "<script language=javascript>alert('".$_SESSION["myrecordid"]."')</script>";
Notes for anyone else doing this...

  1. I tried with the onload and the before display events however my javascript accesses fields on the page and would not run. Probably the fields were not in existence at this point.
  2. The code snippet worked fine - I put the snippet in the section just above the "save/reset/back to list buttons.