ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

'save' data passed in URL segment to be retrieved later on in session - or whatever would do that...

October 17, 2009 4:43am

Subscribe [2]
  • #1 / Oct 17, 2009 4:43am

    Synergy3C

    18 posts

    Hi EE and Communit-EE!

    I don’t know how to explain (or what to call what needs to be done) in order to find an answer to this question in the forum, so sorry if it is answered elsewhere.

    At present I have a landing page using a form that is set to capture a referral code included in segment_2 (eg: http://www.somedomain.com/site/code=123553).  I have then created a hidden field that stores that segment_2 data and inserts it into the form entry data when submitted along with other user input.  I’m not using any PHP, just native EE functionality.

    This works fine (am using FreeeForm). But if the user leaves that page to go to another page(s) on the site, that segment data is then lost.

    What I would like to do is ‘store’ that reference code in the user’s session (I assume it is how it would be done) so that it is ‘remembered’ as the user goes to other pages. 

    At the time when the user does choose to fill in a form (on any page) that segment_2 referral code is then retrieved from storage and inserted into the form entry data (in any given page with a form).

    I figure it is possible, I just don’t know what all this is called in order to find an answer myself.

    Would greatly appreciate some ‘Session Management 101 and 102’ advice - assuming this is what I need to know to achieve my goals.

    Cheers for the advice - the EE community ROCKS!

  • #2 / Oct 17, 2009 10:14am

    Focus Lab Dev Team

    1129 posts

    If you are using Freeform you should be able to just use the return parameter to achieve this. Something like

    {exp:freeform:form form_name="my_form" required="name|email" return="my/template/{segment_2}"}
    form stuff
    {/exp:freeform:form}

    This, in theory, should just pass the segment to the next page and will prevent you from having to create a session variable.

  • #3 / Oct 17, 2009 6:19pm

    Synergy3C

    18 posts

    HI Erik, Thanks for that.  I didn’t think about that option.. and that is very good to know. 

    However what if the user does not enter any data into the form that they first land on when they hit my site - but instead they move to another page; entering their data into another form on another page later on?

    Wouldn’t I then have to have a session variable to store the original segment_2 data for retrieval in the form submit?

    Your note on session ‘variable’ has given me clue for more research, though.  Is EE global variable and session variable related?  Do they interact? 

    Thanks for the help, all.

  • #4 / Oct 17, 2009 7:07pm

    Focus Lab Dev Team

    1129 posts

    Oh I see what you’re looking for now. Initially I didn’t realize you were capturing a referral code for a session. It makes more sense to me why you used the word session now. Sorry!

    You can manually set a session variable if you have PHP enabled in your template of the landing page. You would need to call in the EE Session object and could do something like this:

    {if segment_3 != ""}
    <?php
    global $SESS;
    $SESS->referral_code = "{segment_3}";
    ?>
    {/if}

    Then in any other page you should be able to call that variable with this:

    <?php
    global $SESS;
    echo (isset($SESS->referral_code)) ? $SESS->referral_code : '' ;
    ?>
  • #5 / Oct 17, 2009 7:26pm

    Synergy3C

    18 posts

    Ok! That’s great, mate, thanks.  Rather than asking you more how to’s on what you just said.. I will learn what can to implement your help.  I’ll get back to you with my prgress an dmore queion (if that’ ok). 

    I’ll assume that the Session object need to be inserted in the <head> section… and will go from there.

    Thanks much.

  • #6 / Oct 17, 2009 7:28pm

    Focus Lab Dev Team

    1129 posts

    Glad to help! 😊

    I’ll assume that the Session object need to be inserted in the <head> section… and will go from there.

    Actually it can go anywhere in your template as far as I know.

  • #7 / Oct 17, 2009 7:32pm

    Focus Lab Dev Team

    1129 posts

    Additional note:

    Just make sure it’s only on your landing page because otherwise it will take {segment_2} for any page URI if it exists.

  • #8 / Oct 17, 2009 7:33pm

    Synergy3C

    18 posts

    Much obliged. One final, lame, question. For this instance, when allowing PHP in the template, am I to set the parsing stage to input or output?

    I’m using the one single template for all the pages of the site, using blog entries for content.

  • #9 / Oct 17, 2009 7:38pm

    Focus Lab Dev Team

    1129 posts

    Much obliged. One final, lame, question. For this instance, when allowing PHP in the template, am I to set the parsing stage to input or output?

    I’m using the one single template for all the pages of the site, using blog entries for content.

    You would want Output processing so that it’s the last thing done (Docs: PHP in Template)

    Since your template is like that you might want to do something more like this:

    {if segment_2 == "code" && segment_3 != ""}
    <?php
    global $SESS;
    $SESS->referral_code = "{segment_3}";
    ?>
    {/if}

    This way the variable is only set if the landing page has “code” in the second segment (still assuming your URI would be http://www.somedomain.com/site/code/123553/).

  • #10 / Oct 17, 2009 8:04pm

    Synergy3C

    18 posts

    Ok! Well, I was not able to get session to store and echo the segment_3 code from page to page.. (as it was just not being inserted into the hidden field in the ‘echo’ command) but what I have done is used your advice to get the segment inserted into each navigation link so it is carried through..

    A bit more manual, but seems to work. I just need to make sure that any internal links have that same property.  This seems an easy fix for this small site.

    Thanks much! Here is what I did… 
    IN the <head> section

    {if segment_3 != ""}
    <?php
    global $SESS;
    $SESS->referral_code = "{segment_3}";
    ?>
    {/if}

    In my navigation links:

    {exp:weblog:entries weblog="weblog" sort="asc" dynamic="off" orderby="date"}
    <li id="{title}"><a{if '{embed:my_location}'=="{title}"} class="active"{/if} href="{site_url}site/{url_title}/<?php
    global $SESS;
    echo (isset($SESS->referral_code)) ? $SESS->referral_code : '' ;
    ?>" ><span class="l"></span><span class="r"></span><span class="t">{title}</span></a></li>
    {/exp:weblog:entries}

    This way the segment_3 referral code is carried through by the navigation links. The form can then just extract the segment_3 code from any page as it is existing in the URI.

    Thanks Erik.  I may not have been able to implement exactly as you recommended, but I did find a solution within my capability level.  Cheers

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases