Copied to clipboard

Flag this post as spam?

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


  • Matthew Kirschner 323 posts 609 karma points
    Jul 09, 2015 @ 15:15
    Matthew Kirschner
    0

    Save Input Fields for Custom Member Properties

    Using the Umbraco RegisterModel, how do I save custom properties from an input field?

    Here's what I have done so far:

    I created a Register Member macro using the relevant Umbraco snippet. I then added the macro to a page and saved. This registration macro works well right off the bat, even with custom properties. Here's the view logic that achieves this:

    @if (registerModel.MemberProperties != null)
    {
        foreach (UmbracoProperty t in registerModel.MemberProperties)
        {
            @Html.LabelFor(m => t.Value, t.Name)
            @Html.EditorFor(m => t.Value)
            @Html.HiddenFor(m => t.Alias)
            <br />
        }
    }
    

    I have two problems with this:

    1. It spits out all properties, even ones I don't want
    2. I have no way of re-ordering the fields

    I figured it would be easy to solve this by simply removing the loop and adding the fields manually using the following code:

    @{
        var firstNameMemberProperty = registerModel.MemberProperties.Find(x => x.Alias.Contains("firstName"));
    }
    
    //BeginUmbracoForm
    
    @if (firstNameMemberProperty != null)
    {
        @Html.LabelFor(m => firstNameMemberProperty.Value, firstNameMemberProperty.Name)
        @Html.EditorFor(m => firstNameMemberProperty.Value)
        @Html.HiddenFor(m => firstNameMemberProperty.Alias)
    }
    

    This code rendered the custom property field, firstName, just fine, but when I submit the form the property is never saved.

    Can anyone tell me why? Is there a better method I should be using to have more control over my custom member properties when registering a member?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies