Copied to clipboard

Flag this post as spam?

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


  • Piotr Bach 15 posts 129 karma points c-trib
    Nov 26, 2016 @ 17:40
    Piotr Bach
    0

    Validation messages while creating members

    Hi, all.
    I'm working on a form where the user can create a member account - there is a localization issue. I am using client side validation with build in registration model - but I can't control the messages ;( The validation messages ("Please enter a valid e-mail address", "A member with this username already exists", "The password is not strong enough", etc) should appear in a specific language - depending on the current language settings (en, de, pl).

    @{
    
    var registerModel = Members.CreateRegistrationModel();
    
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
    Html.RequiresJs("/umbraco_client/ui/jquery.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
    Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    }
    
    
    
    @using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
    {
        @Html.ValidationSummary("registerModel", true)
    
        <div class="field-row">
            @Html.LabelFor(m => registerModel.Email)
            @Html.TextBoxFor(m => registerModel.Email, new { @class = "le-input" })
            @Html.ValidationMessageFor(m => registerModel.Email)
        </div>
        <div class="field-row">
            @Html.LabelFor(m => registerModel.Password)
            @Html.PasswordFor(m => registerModel.Password, new { @class = "le-input" })
            @Html.ValidationMessageFor(m => registerModel.Password)
        </div>
    
        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 />
            }
        }
    
        @Html.HiddenFor(m => registerModel.MemberTypeAlias)
        @Html.HiddenFor(m => registerModel.RedirectUrl)
        @Html.HiddenFor(m => registerModel.UsernameIsEmail)
    
        <button class="le-button huge">Create account</button>
    }
    

    The html output:

    <div class="field-row">
            <label for="registerModel_Email">Email</label>
            <input class="le-input" data-val="true" data-val-regex="Please enter a valid e-mail address" data-val-regex-pattern="[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" data-val-required="The Email field is required." id="registerModel_Email" name="registerModel.Email" type="text" value="[email protected]">
            <span class="field-validation-valid" data-valmsg-for="registerModel.Email" data-valmsg-replace="true"></span>
        </div>
    

    Hoping someone might help point me in the right direction.
    Thanks, Piotr

  • Pawel Bres 39 posts 160 karma points c-trib
    Nov 29, 2016 @ 06:56
    Pawel Bres
    1

    Hi Piotr,

    unfortunately it seems that ModelState's errors are hardcoded inside default RegisterController.

    You can find it here https://github.com/umbraco/Umbraco-CMS/blob/release-7.5.4/src/Umbraco.Web/Controllers/UmbRegisterController.cs#L48

    What you can do is to copy UmbRegisterController code and create your own controller with dictionary items instead of hardcoded strings.

    Please let me know if you have any more questions, Cheers

  • Piotr Bach 15 posts 129 karma points c-trib
    Nov 29, 2016 @ 08:01
    Piotr Bach
    0

    Hi Pawel,
    it looks like good idea, so I'll give it a try. It would be nice if RegisterModel had virtual properties, so we could also easily override @DataAnnotations.
    Thx a have a nice day M8.

Please Sign in or register to post replies

Write your reply to:

Draft