Forums

Retrieve session data after save to session action

tshirley 15 Jul, 2018
Hello,

I found another topic similar, but the solution in that topic didn't work for me.

I set up 2 forms.

In form 1 I collect some data then in the submit event I do a "save to session" action and redirect to Form 2. The name of this action is "save_to_session17".

In form 2, based on the reply in the earlier topic, I place php code
\GApp::session()->get("save_to_session17.var", "default");

$this->data['var'] = $this->get("save_to_session17","default");

return $this->data['var'];
before the display_section action and then a debugger which shows:

Array
(
    [option] => com_chronoforms6
    [chronoform] => test2
    [_ga] => GA1.2.1332169317.1437286808
    [c0b3da5e2c719fc1d8c4287f74bf65ff] => 3sldcvmijuqkr5g79urlaqquc5
    [69acbdca18c366bd0fda2fd3c2f798f1] => gp248pj9lgru6thqnmtlthbe86
    [Itemid] => 
    [var] => default
)
Array
(
    [php4] => Array
        (
            [returned] => default
            [var] => default
        )

)
So obviously it isn't getting the session data returned in the second form, but I can't see what I have done wrong.

Hope someone can help here..

Cheers

Tim
tshirley 15 Jul, 2018
Sorry, I should also say there is a redirect which calls Form 2 from the Form 1 submit event.
tshirley 15 Jul, 2018
Hi,

Thank you - I was certainly seeing it as more complicated than it is. Now I can see the session data, but I am having trouble getting it decoded.

The string returned is json so i tried to json_decode it, but it didn't return anything. I tried a json parser which gave it the OK.

So then I simply copy/pasted the string and hard coded it as a test, and it decoded perfectly.

The php code is this:

$this->data['sess'] = '{session:save_to_session17}';
$this->data['sess_decode'] = json_decode($this->data['sess'], true);

$this->data['test'] = '{"option":"com_chronoforms6","chronoform":"test","event":"submit","firstname":"Tim","lastname":"S","calendar5":"2018-07-16 00:00:00","AI":"","button2":"","_ga":"GA1.2.1332169317.1437286808","c0b3da5e2c719fc1d8c4287f74bf65ff":"3sldcvmijuqkr5g79urlaqquc5","69acbdca18c366bd0fda2fd3c2f798f1":"gp248pj9lgru6thqnmtlthbe86","Itemid":null}';
$this->data['test2'] = json_decode($this->data['test'], true);
and the debug returns this:
Array
(
    [option] => com_chronoforms6
    [chronoform] => test2
    [_ga] => GA1.2.1332169317.1437286808
    [c0b3da5e2c719fc1d8c4287f74bf65ff] => 3sldcvmijuqkr5g79urlaqquc5
    [69acbdca18c366bd0fda2fd3c2f798f1] => gp248pj9lgru6thqnmtlthbe86
    [Itemid] => 
    [sess] => {"option":"com_chronoforms6","chronoform":"test","event":"submit","firstname":"Tim","lastname":"S","calendar5":"2018-07-16 00:00:00","AI":"","button2":"","_ga":"GA1.2.1332169317.1437286808","c0b3da5e2c719fc1d8c4287f74bf65ff":"3sldcvmijuqkr5g79urlaqquc5","69acbdca18c366bd0fda2fd3c2f798f1":"gp248pj9lgru6thqnmtlthbe86","Itemid":null}
    [sess_decode] => 
    [test] => {"option":"com_chronoforms6","chronoform":"test","event":"submit","firstname":"Tim","lastname":"S","calendar5":"2018-07-16 00:00:00","AI":"","button2":"","_ga":"GA1.2.1332169317.1437286808","c0b3da5e2c719fc1d8c4287f74bf65ff":"3sldcvmijuqkr5g79urlaqquc5","69acbdca18c366bd0fda2fd3c2f798f1":"gp248pj9lgru6thqnmtlthbe86","Itemid":null}
    [test2] => Array
        (
            [option] => com_chronoforms6
            [chronoform] => test
            [event] => submit
            [firstname] => Tim
            [lastname] => S
            [calendar5] => 2018-07-16 00:00:00
            [AI] => 
            [button2] => 
            [_ga] => GA1.2.1332169317.1437286808
            [c0b3da5e2c719fc1d8c4287f74bf65ff] => 3sldcvmijuqkr5g79urlaqquc5
            [69acbdca18c366bd0fda2fd3c2f798f1] => gp248pj9lgru6thqnmtlthbe86
            [Itemid] => 
        )

)
As far as I can see the hard coded string is identical to the session data (I copy/pasted it) so I don't know why it would behave differently for the two scenarios.

Thanks for all your patience and help.

Tim
tshirley 15 Jul, 2018
Hi,

Thanks again... but no luck I'm afraid.

Changed that shortcode to
$this->data['sess'] = '{session/jsonde:save_to_session17}';
and got no result back from the shortcode. So then tried:
$this->data['sess'] = '{session/json_de:save_to_session17}';
and it was the same as without the /json_de :
Array
(
    [option] => com_chronoforms6
    [chronoform] => test2
    [_ga] => GA1.2.1332169317.1437286808
    [c0b3da5e2c719fc1d8c4287f74bf65ff] => 3sldcvmijuqkr5g79urlaqquc5
    [69acbdca18c366bd0fda2fd3c2f798f1] => gp248pj9lgru6thqnmtlthbe86
    [Itemid] => 
    [sess] => {"option":"com_chronoforms6","chronoform":"test","event":"submit","firstname":"Tim","lastname":"S","calendar5":"2018-07-16 00:00:00","AI":"","button2":"","_ga":"GA1.2.1332169317.1437286808","c0b3da5e2c719fc1d8c4287f74bf65ff":"3sldcvmijuqkr5g79urlaqquc5","69acbdca18c366bd0fda2fd3c2f798f1":"gp248pj9lgru6thqnmtlthbe86","Itemid":null}
    [sess_decode] => 
    [test] => {"option":"com_chronoforms6","chronoform":"test","event":"submit","firstname":"Tim","lastname":"S","calendar5":"2018-07-16 00:00:00","AI":"","button2":"","_ga":"GA1.2.1332169317.1437286808","c0b3da5e2c719fc1d8c4287f74bf65ff":"3sldcvmijuqkr5g79urlaqquc5","69acbdca18c366bd0fda2fd3c2f798f1":"gp248pj9lgru6thqnmtlthbe86","Itemid":null}
    [test2] => Array
        (
            [option] => com_chronoforms6
            [chronoform] => test
            [event] => submit
            [firstname] => Tim
            [lastname] => S
            [calendar5] => 2018-07-16 00:00:00
            [AI] => 
            [button2] => 
            [_ga] => GA1.2.1332169317.1437286808
            [c0b3da5e2c719fc1d8c4287f74bf65ff] => 3sldcvmijuqkr5g79urlaqquc5
            [69acbdca18c366bd0fda2fd3c2f798f1] => gp248pj9lgru6thqnmtlthbe86
            [Itemid] => 
        )

)
Array
(
)
I also tried:
$this->data['sess'] = '{session/json_decode:save_to_session17}';
and got the same as above.

Cheers

Tim
healyhatman 15 Jul, 2018
Sorry, it's {session.jsonde:variable}
tshirley 15 Jul, 2018
Hmmm

Not having much luck here.
$this->data['sess'] = '{session.jsonde:save_to_session17}';
returned nothing.
$this->data['sess'] = '{session.json_de:save_to_session17}';
returned the string but did not allow me to decode it (just as if it wasn't there).

Cheers
healyhatman 15 Jul, 2018
Right well since you're doing this in PHP why not just use json_decode() ?
tshirley 15 Jul, 2018
If you see a few posts ago, #379059 I tried that but it would not decode the returned string for some reason and just returned nothing.
But when I copy/pasted the string and assigned it to a php variable, it decoded fine.

I am in fact trying to upgrade these working forms from V5 to V6. I could always leave them alone, but I'd prefer to have everything in V6.

Cheers
healyhatman 15 Jul, 2018
Well you can't use shortcode in PHP in V6.
tshirley 15 Jul, 2018
OK... well I have always used PHP for this kind of thing, so what is the preferred approach in V6?

I am happy to change my ways.

All I need is some functionality that is the equivalent of "Session to Data" in V5.

Cheers
healyhatman 15 Jul, 2018
well how exactly are you wanting to use the session variable? What's the end goal for the data?
tshirley 15 Jul, 2018
It is a specialised payment gateway situation.

The client enters some data in a form then I redirect them off to another form that manages the payment gateway functions. I have several different forms that need the payment gateway so the gateway form is a sort of function and has no display data. When the gateway process has concluded it redirects to an event in the calling form, to complete the process. It isn't really a shop, since the calling forms are quite specialised for the business we conduct.

So I want to restore the original session data on return from the gateway.

Another possible strategy would be a temporary data save to a table in the calling form, reading it back in the event after the gateway function.

Most of my V6 conversion has gone well.

Cheers

Tim
healyhatman 16 Jul, 2018
Use a multi page action. There's a demo form showing you how to use it.
This topic is locked and no more replies can be posted.