0
votes

I want to sign up new members on my Umbraco website, and give them access to a reserved area.
I need to collect some additional infos from them, like their first name, last name, company name, phone number etc.


So, for the back-end, in the Member section of my Umbraco website, I did this:

  • created a new MemberType, called "memberWebsite"
  • added a new tab "Additional Infos" to my "memberWebsite" MemberType
  • inside the new tab I've added my new custom properties: First Name, Last Name, Company Name, etc
  • all of these properties have "Textstring" editor
  • all of these properties have checkbox "Member can edit" and "Show on member profile" checked

For the front-end, I've created a new partial view for the registration form of the new member, using the "Register Member" snippet provided by Umbraco.


I've only changed the member type of the registerModel, specifying my new MemberType "memberWebsite", like suggested in the snippet comment.

@*
        You can specify a custom member type alias in the constructor, the default is 'Member'    
        for example, to use 'Custom Member' you'd use this syntax:

        var registerModel = Members.CreateRegistrationModel("Custom Member");
    *@

//var registerModel = Members.CreateRegistrationModel();
var registerModel = Members.CreateRegistrationModel("memberWebsite");

The fields for the new member custom properties are correctly shown in the registration page.
I fill them with some values, and then click on the submit button.
I expect to find these values on the new member created, but only the standard fields are saved (e.g. Name, Email, Password).
The custom properties are completely blank, like I never filled them.

How can I get the custom properties saved correctly with the entered values?
PS: I'm running Umbraco 7.14.0.

2

2 Answers

0
votes

You'll need to specify which member properties you want to populate. Try the following:

var model = Members.CreateRegistrationModel("memberWebsite");
model.MemberProperties.Add(new UmbracoProperty { Name = "Full name", Alias = "fullName", Value = "Mikkel Johannsen" });
0
votes

Ok, I found a workaround for the problem.

Code from the "Register Member" snippet [NOT WORKING]

@if (registerModel.MemberProperties != null)
        {
            for (var i = 0; i < registerModel.MemberProperties.Count; i++)
            {
                @Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)

                @Html.EditorFor(m => registerModel.MemberProperties[i].Value)
                @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
                <br />
            }


        }

Instead of looping through the MemberProperties array with the index i, I was able to access the properties by retrieving them one by one. I used the actual index number instead of the variable i.

New code [WORKING]

@if (registerModel.MemberProperties != null)
        {
            // first property
            @Html.LabelFor(m => registerModel.MemberProperties[0].Value, registerModel.MemberProperties[0].Name)

            @Html.EditorFor(m => registerModel.MemberProperties[0].Value)
            @Html.HiddenFor(m => registerModel.MemberProperties[0].Alias)
            <br />

            // second property
            @Html.LabelFor(m => registerModel.MemberProperties[1].Value, registerModel.MemberProperties[1].Name)

            @Html.EditorFor(m => registerModel.MemberProperties[1].Value)
            @Html.HiddenFor(m => registerModel.MemberProperties[1].Alias)
            <br />

            // ... and so on for all the other MemberProperties defined in my MemberType
            }
        }

For some reason, the for loop was adding the prefix "CS$<>8__locals1" to all of the properties attributes. The Alias of the properties passed by the registration form didn't match the Alias of the properties defined in the MemberType.

With this fix, the Alias match and the values of the properties are correctly saved on the new member created.