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 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.
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.
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.
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, 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 :|
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).
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?
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...
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. :\
protectedoverridevoid 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)
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:
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.
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)
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
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.
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.
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
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.
Anthony,
Exactly what I did so that i could do contour multi step form which has a stepbar showing progress.
Regards
Ismail
So you can still do that with the current version of contour. Nice!
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?
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
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
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
Hi Greg,
The cookie stores the record id , cookie name format should be like this:
contour_pageid_formid
Comment author was deleted
But be sure to only remove it when it's not a postback, since it's also used for the navigation between steps
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?
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
That shoudln't be a problem, it should create a new record instead of resuming the old one
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. :\
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
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 ...)
Yup thats the one thanks... so i'm getting the cookie name no probs:
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:
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??
Here's the full code:
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
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
Hi Greg,
Just tested and this works:
Guess in your example you simply needed to add the cookie again ( Response.Cookies.Add(contourCookie); )
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 :)
is working on a reply...