data['username'];?>This code snippet output nothing in "register-p2-form". So how should I use "D2S" and "S2D" correctly and be able to get the value (e.g. value in 'username' field ) from the previous form?I really appreciate any kind suggestions. Cheers!"> How to get session data - Forums

Forums

How to get session data

flyeminent 13 Jul, 2011
Hello everyone,
Fist, I understand this topic is being discussed a lot in this forum. However, I have tried searching for related posts, it seemed that I couldn't find the exact solution.
The question is simple, how to use "Data to Session" and "Session to Data" across two or more forms?
I did try to play around these two actions.
Suppose I have first form "register-p1-form" and add "Data to Session" action into the form's "OnSubmit" event. I also configure the "Data to Session" and put "BASIC_INFO" as the session key.
Then I create second form "register-p2-form" and add "Session to Data" action into the form's "OnLoad" event. Now how do I get the data with the key "BASIC_INFO" in the session using PHP. (or how do I get the data from the previous form)
I wrote the php code just after "Session to Data" action as follows:

<?php
  $session =& JFactory()::getSession();
  $form = $session->get("BASIC_INFO");
  echo $form->data['username'];
?>

This code snippet output nothing in "register-p2-form". So how should I use "D2S" and "S2D" correctly and be able to get the value (e.g. value in 'username' field ) from the previous form?
I really appreciate any kind suggestions. Cheers!
GreyHead 14 Jul, 2011
Hi flyeminent ,

The Data to Session action adds the stored data to the $form->data array so you should be able to use just
<?php
echo $form->data['username'];
?>


Bob

PS - Be careful redefining $form, ChronoForms uses this for the current instance of the form and you may over-write the whole form.
flyeminent 15 Jul, 2011
Hi Bob,
if

<?php
echo $form->data['username'];
?>

is working, what is the "Key" value used for? Based on the example I posted before, may I use

<?php
echo $BASIC_INFO->data['username'];
?>

to access the previous form (because I put "BASIC_INFO" as the session key)? If I never specify key, shall I get the username value of "register-p1-form" in "register-p2-form" by using

<?php
echo $register-p1-form->data['username'];
?>
?
This topic is locked and no more replies can be posted.