Copied to clipboard

Flag this post as spam?

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


  • Tom Bruce 122 posts 506 karma points
    Feb 06, 2018 @ 09:01
    Tom Bruce
    0

    How to Create Register Member Page

    Hi folks, does anyone know the Umbraco TV link for creating a register page.

    I can’t seem to find it, I was watching the videos last month, but now I can’t seem to find them!

  • Alex Brown 129 posts 620 karma points
    Feb 06, 2018 @ 09:09
    Alex Brown
    100

    This module goes through members and logging in, is this what you mean?

    https://umbraco.tv/videos/umbraco-v7/developer/fundamentals/member-api/introduction/

  • Claushingebjerg 899 posts 2448 karma points
    Feb 06, 2018 @ 09:52
    Claushingebjerg
    1

    Hi Tom

    Theres actually a built in partial snippet to do this :)

    enter image description here

  • Tom Bruce 122 posts 506 karma points
    Feb 06, 2018 @ 09:58
    Tom Bruce
    0

    Hi Claushingebjerg,

    The built in one has a bug, the core server side validation for member email address will not accept higher case within the email.

  • Anthony Powell 13 posts 47 karma points
    Apr 30, 2021 @ 05:30
    Anthony Powell
    1

    For simplicity's sake I'm just going to say. Yes you can use the existing snippet.

    But if you need to attach more work flow into it. You'll need to peak that the existing code in Umbraco's "UmbRegisterController"

    Here is the code they are using internally. Modify to suit...

    [HttpPost]
        [ValidateAntiForgeryToken]
        [ValidateUmbracoFormRouteString]
        public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")]RegisterModel model)
        {
            if (ModelState.IsValid == false)
            {
                return CurrentUmbracoPage();
            }
    
            // U4-10762 Server error with "Register Member" snippet (Cannot save member with empty name)
            // If name field is empty, add the email address instead
            if (string.IsNullOrEmpty(model.Name) && string.IsNullOrEmpty(model.Email) == false)
            {
                model.Name = model.Email;
            }
    
            MembershipCreateStatus status;
            var member = Members.RegisterMember(model, out status, model.LoginOnSuccess);
    
            switch (status)
            {
                case MembershipCreateStatus.Success:
    
                    TempData["FormSuccess"] = true;
    
                    //if there is a specified path to redirect to then use it
                    if (model.RedirectUrl.IsNullOrWhiteSpace() == false)
                    {
                        return Redirect(model.RedirectUrl);
                    }
                    //redirect to current page by default
    
                    return RedirectToCurrentUmbracoPage();
                case MembershipCreateStatus.InvalidUserName:
                    ModelState.AddModelError((model.UsernameIsEmail || model.Username == null)
                        ? "registerModel.Email"
                        : "registerModel.Username",
                        "Username is not valid");
                    break;
                case MembershipCreateStatus.InvalidPassword:
                    ModelState.AddModelError("registerModel.Password", "The password is not strong enough");
                    break;
                case MembershipCreateStatus.InvalidQuestion:
                case MembershipCreateStatus.InvalidAnswer:
                    // TODO: Support q/a http://issues.umbraco.org/issue/U4-3213
                    throw new NotImplementedException(status.ToString());
                case MembershipCreateStatus.InvalidEmail:
                    ModelState.AddModelError("registerModel.Email", "Email is invalid");
                    break;
                case MembershipCreateStatus.DuplicateUserName:
                    ModelState.AddModelError((model.UsernameIsEmail || model.Username == null)
                        ? "registerModel.Email"
                        : "registerModel.Username",
                        "A member with this username already exists.");
                    break;
                case MembershipCreateStatus.DuplicateEmail:
                    ModelState.AddModelError("registerModel.Email", "A member with this e-mail address already exists");
                    break;
                case MembershipCreateStatus.UserRejected:
                case MembershipCreateStatus.InvalidProviderUserKey:
                case MembershipCreateStatus.DuplicateProviderUserKey:
                case MembershipCreateStatus.ProviderError:
                    //don't add a field level error, just model level
                    ModelState.AddModelError("registerModel", "An error occurred creating the member: " + status);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
    
            return CurrentUmbracoPage();
        }
    

    Note you can create a new model like this.

    var regModel = RegisterModel.CreateModel();
                regModel.Email = model.Email;
                regModel.Name = $"{model.Name} {model.Surname}";
                regModel.Password = model.Password;
                regModel.Username = model.Email;
                regModel.UsernameIsEmail = false;
                regModel.LoginOnSuccess = false;
    
  • marina.b 11 posts 101 karma points
    May 25, 2021 @ 21:00
    marina.b
    0

    Hi All,

    I am trying to add to the registration example provided (partial view) a checkbox in order to register the privacy acceptance of the registrant. I did not succeed in rendering the checkbox on the registration page.

    I tried the following instruction @Html.CheckBoxFor(m=> registerModel.MemberProperties[0].Value, new {true})

    May be I am lucky and someone has already done it...

    Thanks

  • Alan Mitchell 54 posts 270 karma points c-trib
    Jul 27, 2021 @ 15:00
    Alan Mitchell
    0

    Here's how I added a checkbox to the registration form:

    1. First, ensure your Member Type has a property for the checkbox of type Umbraco.TrueFalse

    2. In the registration macro partial view you will want to render a checkbox for this property rather than a textbox, testing for the alias is the easiest way:

      if (registerModel.MemberProperties[i].Alias == "yourCheckboxProperty")
         {
            @Html.EditorFor(m => registerModel.MemberProperties[i].Value, new { htmlAttributes = new { type = "checkbox", @class="registration-checkbox" } });
            @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias);
         }
      

    This will render an HTML input of type checkbox

    Finally, to get it to behave, add some cheeky jquery to the page:

    // Registration helper
    $(".registration-checkbox").on('change', function (e) {
        $(this).val($(this).is(':checked') ? 1:0);
    });
    

    This will set the value of the input field to 1 or 0 depending on the state of the checkbox. The default registration controller will store this value for you.

    Hope this helps!


    Inspiration / background from this forum post

Please Sign in or register to post replies

Write your reply to:

Draft