I've modified the Form.cshtml to store the state of any form within a logged in Member's record. It automatically creates a new field in the Membertype for each Contour form the member uses. So it saves data along the way very nicely. However it won't load the data into the form when the member returns. Even when Model.RecordValues has the correct values from the Member's record.
I thought I had solved it with the following but the property is read only!
@foreach (FieldViewModel f in fs.Fields)
{
// if (dict[f.Id] != null) f.Value = (string)dict[f.Id]; arrgh this read only so close no cigar!
}
else
{
///
/// Form Member State Storage BEGINS (Insert this code to provide state storage)
///
int pageId = umbraco.NodeFactory.Node.GetCurrent().Id;
string formId = Model.FormId.ToString();
string formGuid="contour_" + formId;
// HttpCookie contourCookie = Request.Cookies["contour_" + pageId + "_" + formId];
Dictionary dict = new Dictionary();
// Only store Form Data for Forms in a certain folder ie. FORM/Store Form (Otherwise Login/Profile form would save state not a good idea).
if (Model.FormName.Contains("Stored Form/"))
{
// if the user logged in?
if (!Request.IsAuthenticated)
{
Signin to store the questionaire....
}
else
{
var m = Member.GetCurrentMember();
string mtAlias = m.ContentType.Alias; // MemberType of the current user.
var mt = MemberType.GetByAlias(mtAlias);
if (mt != null)
{
var mpt = mt.getPropertyType(formGuid);
if (mpt == null)
{
Guid guid = new Guid("67db8357-ef57-493e-91ac-936d305e0f2a"); // Textbox Muliple GUID to store the form state
DataTypeDefinition dt = DataTypeDefinition.GetByDataTypeId(guid);
mt.AddPropertyType(dt, formGuid, Model.FormName);
mt.Save();
}
// If the form's name is updated then update the field name in the membertype.
PropertyType pt = mt.getPropertyType(formGuid);
if (pt.Name != Model.FormName)
{
pt.Name = Model.FormName;
pt.Save();
}
// Load Save
Load Model.RecordValues from Database
string formState = (string)m.getProperty(mpt).Value;
string[] t = formState.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
if (t.Length > 0)
{
for (int i = 0; i < t.Length; i++)
{
string[] pairs = t[i].Split(new char[] { '¦' });
if (pairs.Length == 2)
{
string v = pairs[1]; string k = pairs[0];
if (!dict.ContainsKey(k)) { dict.Add(k, v); }
if (Model.RecordValues.ContainsKey(k)) { Model.RecordValues[k] = v; };
Key: @k Value: @v
}
}
}
if (IsPost)
{
//Save Form State
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("ResumeStep").Append("¦").Append(Model.FormStep).Append("|");
foreach (KeyValuePair pair in Model.RecordValues)
{
sb.Append(pair.Key).Append("¦").Append(pair.Value).Append("|");
}
string result = sb.ToString();
// Remove the final delimiter
result = result.TrimEnd('|');
m.SetProperty(formGuid, result);
m.Save();
Saved!
}
}
}
}
///
/// Form Member Storage Ends
///
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Hope someone can shed some light on it. It's a very useful feature to add to the Contour Form plugin
Thanks,
Gavin
Storing the state of a form for a member
Hi,
I've modified the Form.cshtml to store the state of any form within a logged in Member's record. It automatically creates a new field in the Membertype for each Contour form the member uses. So it saves data along the way very nicely. However it won't load the data into the form when the member returns. Even when Model.RecordValues has the correct values from the Member's record.
I thought I had solved it with the following but the property is read only!
The code is below,
Hope someone can shed some light on it. It's a very useful feature to add to the Contour Form plugin Thanks, Gavin
hello Gavin,
have you figured out on this?
Unfortunately not, I stopped using Contour and started using my own REST App/MVC solution.
Best Regards, Gavin
is working on a reply...