Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Greg Berlin 818 posts 634 karma points
    Dec 07, 2010 @ 01:04
    Greg Berlin
    0

    Contour Caching Form Values on a Multi Step Form - How to Clear?

    I've created a custom field type (an ajax lookup to a data source, displayed  as an autocomplete text box with validation etc).  My field type shows or hides the 'next' button based on whether or not a value from the database has been selected in the autocomplete text box.  It's the first step of a multi-step form, and acts as a prerequisite for the user to meet before they can fill in the rest of the form.

    My code for the field type is here:
      http://our.umbraco.org/forum/umbraco-pro/contour/14568-Ajax-Autocomplete-List-FieldType?p=1

    My field type works perfectly, however it has this bug which I dont know how to fix:

     

    If a user browses to the page with the form for the first time, the new field type displays (its set in a step on its own - the first step on a multi-step form)

    If they fill in and select a value and go next, it works fine

    if they then browse to that page again (via link, or removing the ? from the url and reloading), it takes them straight to step 2

    So essentially it seems Contour is treating that step of the form as filled in, and skipping it.  Any idea why Contour would do that, and how i can stop it from making said assumption?

    My client is going a little ballistic about this, so I'm under huge pressure to get it sorted soon.. hope somebody out there has a solution as it has me stumped... not sure how i could solve it anyway, since it seems to be a contour framework issue.

    thanks heaps

    greg

     

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Dec 07, 2010 @ 08:23
    Sebastiaan Janssen
    0

    Contour stores your progress in a cookie, the logic being that once you complete a step you shouldn't have to see it again. I don't know if there's an easy way to make a "go back" button. What you could try is to somehow detect that there's no querystring and delete the Contour cookie. However, any information that was previously entered will probably also be lost.

    Would love to know if there's a better way though, a "back" button would be good. Maybe it's possible to delete some information in the cookie and still keep the previously entered information. Have a look at the info in the cookie and in your viewstate to find out more about this.


  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Dec 07, 2010 @ 10:56
    Ismail Mayat
    2

    Sebastian, Greg,

    I had this issue with with the step form hack i did  you could half fill form and close it then re open and the form would open on correct page but the steps would be out of synch so i had to read the cookie and then restore the step to the correct step in the step bar.  

    public string StepCookieName { get; set; }
    
    protected override void OnLoad(EventArgs e)
    
            {
    
                if (!IsPostBack)
    
                {
    
                    SetViewStateCurrentStepFromCookie();
    
                }
    
     }
    
    
    private void SetViewStateCurrentStepFromCookie()
    
            {
    
                //if resumed form get step value from cookie
    
                if (Request.Cookies[StepCookieName] != null)
    
                {
    
                    int stepId = 0;
    
                    if (!string.IsNullOrEmpty(Request.Cookies[StepCookieName].Value))
    
                    {
    
                        int.TryParse(Request.Cookies[StepCookieName].Value, out stepId);
    
                        if(stepId!=0)
    
                        {
    
                                ViewState["pgv_pageindex"] = stepId;
    
                        }
    
                    }
    
    
    
                }
    
            }

    please note i created my own form control that inherits from contour form control and i put in my own logic by overriding page_load see here for what i did.

    Regards

    Ismail

     

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Dec 07, 2010 @ 11:26
    Anthony Dang
    1

    I had to do some crazy stuff with contour last year. Maybe this will help:

    http://www.farmcode.org/post/2010/03/26/Regionalizing-validation-messages-and-regex-in-Umbraco-Contour.aspx

    I'm not sure about the new Contour, but the last version puts a file called RenderForm.ascx under \usercontrols\umbracoContour\ in your project. You can write your own codebehind to inherit from Umbraco.Forms.UI.Usercontrols.RenderForm, where you can override the prerender event of the form to do anything.

     


     


  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Dec 07, 2010 @ 12:32
    Ismail Mayat
    0

    Anthony,

    Exactly what I did so that i could do contour multi step form which has a stepbar showing progress.

    Regards

    Ismail

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Dec 07, 2010 @ 12:41
    Anthony Dang
    0

    So you can still do that with the current version of contour. Nice!

     

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 13:03
    Greg Berlin
    0

    UGGGHHHHHHHH... stupid forum keeps ditching my posts.. its happened to me at least a dozen times now.  SO frustrating.

    I'm stuck with the cookie.. I dont have any cookies with an integer value that look like they'd be storing the current step.

    Ismail, i notice you have a public property "StepCookieName"... where are you setting the value of that?

    Is the current step maybe getting stored in the session, and not a specific cookie?

    Any other suggestions how i can determine which step we should be at in the form?

     

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 13:18
    Greg Berlin
    0

    Ismail, I notice you check the following viewstate value: ViewState["pgv_pageindex"] ... but it seems to be always null for me... is this the correct value?

    Ugh, i'm really stuck with this.. i wish i had the source code to figure out what contour is doing, and how it's loading the form steps.  really hoping somebody can help me with this soon :|

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #ae211f} span.s1 {color: #000000}

  • Comment author was deleted

    Dec 09, 2010 @ 13:29

    Hi Greg,

    That's the way it's setup, when a person enters a multistep form and doesn't get to the end, the next time he goes to the form he'll resume the record ...

    There is no default way of disabling this. What you could to is add some code that removed the cookie when the pages loads (initial load not on a postback).

    Regards,
    Tim

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 13:36
    Greg Berlin
    0

    Yeah, that's what i'm trying to do Tim, but what cookie is it?  I dont seem to have a cookie set that has an integer value that would represent a step number... sure its stored in a cookie?

  • Comment author was deleted

    Dec 09, 2010 @ 13:38

    Hi Greg,

    The cookie stores the record id , cookie name format should be like this:

    contour_pageid_formid

     

  • Comment author was deleted

    Dec 09, 2010 @ 13:43

    But be sure to only remove it when it's not a postback, since it's also used for the navigation between steps

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 13:59
    Greg Berlin
    0

    Yup, found the cookie... but clearing the value does not cause the form to go back to the beginning.  Do i need to reload the page?

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 14:05
    Greg Berlin
    0

    Egh... I'm setting the cookie value to null, then redirecting back to the the same page (reloading it), but contour is resetting the cookie on each page load...

     

  • Comment author was deleted

    Dec 09, 2010 @ 14:07

    That shoudln't be a problem, it should create a new record instead of resuming the old one

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 14:15
    Greg Berlin
    0

    Perhaps, but how do you suggest i reload the page?  calling "Response.Redirect(Request.Url.ToString());" causes it to get stuck in an endless loop cos i'm checking if the cookie is set, if so delete and redirect.

    I guess i could force a postback via a javascript call, but that's just getting really ugly. :\

    
    
    
    
    
    
    
    
    

            protected override void OnLoad(EventArgs e)

            {

                if (!IsPostBack)

                {

                    if (Request.Cookies["contour_1353_2843a2da-fc6a-4229-ab59-5d8f3b552c7b"] != null)

                    {

                        if (Request.Cookies["contour_1353_2843a2da-fc6a-4229-ab59-5d8f3b552c7b"].Value != null)

                        {

                            Request.Cookies["contour_1353_2843a2da-fc6a-4229-ab59-5d8f3b552c7b"].Value = null;

                            // Contour resetting the cookie, so getting stuck in endless loop...

                            Response.Redirect(Request.Url.ToString());

                        }

                    }

                }

            }

     

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 14:16
    Greg Berlin
    0

    Also, i've found teh form Id (Page.FormGuid i think it was).. how to get the page id?  can't find the umbraco api doco right now.. :\

  • Comment author was deleted

    Dec 09, 2010 @ 14:21

    reference umbraco.dll

    and then you get get it trough

    umbraco.presentation.nodefactory.node.getcurrent().id

    (not 100% on the casing but it should get you there ...)

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 14:40
    Greg Berlin
    0

    Yup thats the one thanks... so i'm getting the cookie name no probs:

    
    
    
    
    
    
    
    
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas}
    p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; min-height: 11.0px}
    span.s1 {color: #4200fe}
    span.s2 {color: #49a2bc}
    span.s3 {color: #ae211f}
    
    
    
    

            private string CurrentPageCookie

            {

                get

                {

                    int pageId = umbraco.presentation.nodeFactory.Node.GetCurrent().Id;

                    string formGuid = this.FormGuid;

                    return String.Format("contour_{0}_{1}", pageId, formGuid);

                }

            }

     

    But still not sure how to go about forcing contour to start at the beginning of the form once i've cleared teh cookie... I've added a new session variable to check against, to prevent the endless redirecting loop... but contour is still not starting at the first step.  Here's my code:

    
    
    
    
    
    
    
    
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas}
    p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #009200}
    p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; min-height: 11.0px}
    span.s1 {color: #4200fe}
    span.s2 {color: #49a2bc}
    span.s3 {color: #ae211f}
    span.s4 {color: #000000}
    
    
    
    

            protected override void OnLoad(EventArgs e)

            {

                if (!IsPostBack)

                {

                    if (Request.Cookies[CurrentPageCookie] != null)

                    {

                        if (!(Session["Redirected"] != null && (bool)Session["Redirected"]) && Request.Cookies[CurrentPageCookie].Value != null)

                        {

                            Request.Cookies[CurrentPageCookie].Value = null;

                            Session["Redirected"] = true;

                            // Contour resetting the cookie, so getting stuck in endless loop...

                            Response.Redirect(Request.Url.ToString());

                        }

                    }

                }

                else

                    Session["Redirected"] = false;

            }

     

     

    The logic is working fine, its clearing the cookie once, redirecting, reloading the page, and on the second time skipping the cookie clearing and redirect operation, but still its skipping the first step. 

    What am i missing??

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 14:45
    Greg Berlin
    0

    Here's the full code:

        public partial class KIND_RenderForm : RenderForm

      {

            private string CurrentPageCookie

            {

                get

                {

                    int pageId = umbraco.presentation.nodeFactory.Node.GetCurrent().Id;

                    string formGuid = this.FormGuid;

                    return String.Format("contour_{0}_{1}", pageId, formGuid);

                }

            }

            protected override void OnInit(EventArgs e)

            {

                base.OnInit(e);

            }

          protected override void OnLoad(EventArgs e)

            {

                if (!IsPostBack)

                {

                    if (Request.Cookies[CurrentPageCookie] != null)

                    {

                        if (!(Session["Redirected"] != null && (bool)Session["Redirected"]) && Request.Cookies[CurrentPageCookie].Value != null)

                        {

                            Request.Cookies[CurrentPageCookie].Value = null;

                            Session["Redirected"] = true; // To prevent getting stuck in endless loop...

                            Response.Redirect(Request.Url.ToString());

                        }

                    }

                }

                else

                    Session["Redirected"] = false;

            }

        }

  • Greg Berlin 818 posts 634 karma points
    Dec 09, 2010 @ 23:25
    Greg Berlin
    0

    So.... no suggestions?  The original one of clearing that cookie clearly doesn't work.

    It'd be awesome if somebody could look at the source code of Contour and tell me how it's establishing at which step of the form it loads.

    I just thought of something.. perhaps i should set the expiry date of the cookie to a time in the past instead of clearing the value... maybe that'll force contour to start the form again... what do you guys think?  (can't try it now, dont have my dev machine with me unfortunately)

  • Comment author was deleted

    Dec 10, 2010 @ 10:12

    Hi Greg,

    I'll take a look at how you can do this and get back to you with a solution (will be on monday or tuesday).

    Cheers,
    Tim

  • Comment author was deleted

    Dec 13, 2010 @ 14:21

    Hi Greg,

    Just tested and this works:

     

    <script runat="server">
      protected override void OnLoad(EventArgs e){

                if (!IsPostBack)

                {
                    int pageId = umbraco.presentation.nodeFactory.Node.GetCurrent().Id;
                    string formId = "204188fc-509e-43e2-b04e-dcfde2e62158";
                   
                    if (Request.Cookies["contour_"+pageId+"_" +formId] != null)
                    {
                        var contourCookie = Request.Cookies["contour_"+pageId+"_" +formId];
                        contourCookie.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(contourCookie);

                        Response.Redirect(Request.Url.ToString());
                    }
                }

            }
    </script>

    Guess in your example you simply needed to add the cookie again (  Response.Cookies.Add(contourCookie); )

  • Greg Berlin 818 posts 634 karma points
    Dec 13, 2010 @ 20:58
    Greg Berlin
    0

    Thanks Tim - you're a champion!!  

    I can't believe i was so close... i'd thought about expiring the cookie instead of deleting it, but didn't add it back in... doh!

    Thanks again for the fantastic work.. well deserved karma coming your way :)

Please Sign in or register to post replies

Write your reply to:

Draft