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();
}
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...
Here's how I added a checkbox to the registration form:
First, ensure your Member Type has a property for the checkbox of type Umbraco.TrueFalse
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:
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.
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!
This module goes through members and logging in, is this what you mean?
https://umbraco.tv/videos/umbraco-v7/developer/fundamentals/member-api/introduction/
Hi Tom
Theres actually a built in partial snippet to do this :)
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.
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...
Note you can create a new model like this.
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
Here's how I added a checkbox to the registration form:
First, ensure your Member Type has a property for the checkbox of type Umbraco.TrueFalse
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:
This will render an HTML input of type checkbox
Finally, to get it to behave, add some cheeky jquery to the page:
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
is working on a reply...