Sitecore WFFM - Pre-fill form with session data

I am trying to create a WFFM form in Sitecore to edit the current user profile that is stored in a session (other than Sitecore.Context.User.Profile

). To this end, I'm looking for a way to preload form fields with profile data from a session.

Can this be done? I am using Sitecore CMS 6.5 and WFFM 2.3.

+3


source to share


4 answers


It seems that the solution to the problem was a little more complicated. First of all, I moved all profile information from session to Sitecore.Context.User

Profile

. For this, a custom user profile class had to be implemented. Using this approach, I know I need to preload form fields from this custom profile instead of session.

To do this, I created a folder under the content tree called "profile variables", which was the properties of the custom profile that needed to be read, in dot notation. For example: { DisplayName: "Home Telephone", Value: "ContactDetails.HomeTelephone" }

.



Finally, I created a custom WFFM field type based on the Single Line Text field type, which takes another property PreloadField

, taking values ​​from the "Profile Variables" node and in a custom field type OnInit

I read from the user's context profile using reflection of the property value stored in PreloadField

. and assigned this property to a textbox Text

.

Hope this helps someone else find something similar.

0


source


WFFM cannot do this out of the box. We took a different approach to solving the problem. In the rendering of the form /sitecore/layout/Renderings/Modules/Web Forms for Marketers/Form

, you have a field Parameters

where you can add a parameter FormTemplate

with a custom control to display the form:

FormTemplate=/sitecore modules/web/Web Forms for Marketers/Control/CustomSimpleFormAscx.ascx

      



In this custom control, we loop through each field and set the value for the input field based on the custom properties of the user. You can of course improve this in other areas like select, etc. Here's some sample code:

public partial class CustomSimpleFormAscx : SitecoreSimpleFormAscx
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        FillInUserData(this.FieldContainer);
    }

    private void FillInUserData(System.Web.UI.Control control)
    {
        foreach (System.Web.UI.Control child in control.Controls)
        {
            if (child is BaseControl)
            {
                if (child is InputControl)
                {
                    InputControl field = (InputControl)child;
                    field.Text = Sitecore.Context.User.Profile.GetCustomProperty(field.ControlName);
                }
            }

            FillInUserData(child);
        }
    }
}

      

+3


source


I recommend that you decompile the FormRenderer

WebControl and create your own that does this. It is a standard view control for rendering forms through the WFFM module.

0


source


I want to do something like this. In WFFM version 2.3 there are some rules that allow you to set the value of a field from a user profile.

See Actions: Use the default from the User Profile field to the Rules when you select the form field.

You can use the full name, email address, comment, or any other custom property.

One field that is not included is the UserName field. You can write a custom action to return the username field.

0


source







All Articles