Forums

setting session var in submit after email

ajw3208 12 Jul, 2009
Hi all,

I need to set a session variable based on what button is pressed in the submitting form. I have used the code below, but when I check for the variable in the next form as a test, it is empty. Why?
BTW, the button name is not an issue as I use similar code to redirect and this works fine.

aj

<?php
$action = JRequest::getString('rf1sBtn');
$session =& JFactory::getSession();
if (strcasecmp($action, 'Yes') != 0)
{
   $session->set('sessionchangedDetails', 'yes');
}
else
{
$session->set('sessionchangedDetails', 'no');
}
?>
GreyHead 12 Jul, 2009
Hi ajw3208,

I don't know why this should be unless the default values are being cleared by Joomla somewhere. Try declaring your own namespace in the Session and see if this helps
$session->set('sessionchangedDetails', 'yes', 'my_name_space');


Bob
ajw3208 13 Jul, 2009
Hi Bob,

can do, but do you retrieve it as in the code below?

$value= $session->get('sessionchangedDetails', 'my_name_space');


aj
GreyHead 13 Jul, 2009
Hi aj,

It's slightly different
$value= $session->get('sessionchangedDetails', 'default_value', 'my_name_space');


See here for the full syntax.

Bob
ajw3208 14 Jul, 2009
Hi Bob,

Sadly no joy. It looks as if creating a sess variable in that place in CF doesn't work. Be interested to know if Max has any view on why.

I'l have to resort to an option tag (radio or drop) to allow this to be passed in the POST array. not ideal but.....

thanks anyway

aj
GreyHead 14 Jul, 2009
Hi aj,

Odd - ChronoForms is using the session data OK - usually anyhow. I don't understand why it isn't saving for you. (You could try a cookie instead.)

What are you trying to achieve here - maybe there is another way?

Bob
ajw3208 14 Jul, 2009
Hi Bob,

I need to maintain a status throughout a session, and the easiest user input mechanism to set the status via a yes no button selection. (my user community is not real bright so the buttons have to be big. option boxes mean too much thinking) :wink:

I ended up adding the required status yes/no to the URL as GET parameter. the full url string being determined by which button got pressed and this test is performed in the email after submit code box.

I then recover the GET value in the next form and then assign the value to the necessary session variable. a bit messier, but effective.

a real weird one huh!

As always, thanks for the help.

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