Forums

Session data question

ataylor14 16 Dec, 2014
Hello Bob/Admin
Can you send me an example of using code to add data fields to a session, say when a button is clicked, data in various fields on the form get sent to the session array ? And then code to display this data into a custom field?

Many thanks
Kind regards
Amelia
ataylor14 16 Dec, 2014

Can you send me an example of using code to add data fields to a session, say when a button is clicked, data in various fields on the form get sent to the session array ? And then code to display this data into a custom field?



I have managed to use PHP code to load and to get data from a session. Form example in a custom element I display the current session id and ip address of the user in this way:
<?php
$session =& JFactory::getSession();
echo 'Session id is: ' . $session->get( 'idsession', 'empty' );
echo 'Sessions ip address is: ' . $session->get( 'ipadd', 'empty' );
?>

and in Load CSS event I have:
<?php
   session_start();
   $session =& JFactory::getSession();
   $idsession=  $session->getId();
   $ipadd  = $_SERVER ['REMOTE_ADDR'];
   $session->set( 'idsession',$idsession);
   $session->set( 'ipadd',$ipadd);
 ?>
What I do not get is how to add data to a session when a button is clicked (but this button should not be a submit one but should keep the user on the same page). Say I have a textbox and after I fill it in by clicking a button this value gets put into a variable of the current session.

I hope this makes sense.
Thank you
Amelia
Max_admin 19 Dec, 2014
Hi Amelia,

You can write jQuery code to fire when the text is changed or a button is clicked, that code should do an AJAX call to a new form event with your session code.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 23 Dec, 2014
Hi Amelia,

See Max's answer - that is because the session is only available on the server, not in the browser so you have to send the message back to the server with Ajax to have is saved.

Bob
This topic is locked and no more replies can be posted.