Copied to clipboard

Flag this post as spam?

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


  • Aswathi 1 post 71 karma points
    Jun 09, 2019 @ 07:58
    Aswathi
    0

    Show custom validation message in umbraco backed

    Hi All,

    I have added a custom email field to the member type. I am validating the member email with the custom email field for login. So I need to show a validation message in the Umbraco backend for already existing email while creating a new Umbraco member.

    I am trying with the code below but it is not working as expected

    private void MemberSaving(IMemberService sender, Umbraco.Core.Events.SaveEventArgs<IMember> e)
            {
                Random randomNumber = new Random();
                var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                foreach (var memberItem in e.SavedEntities)
                {
                    if (memberItem.ContentType.Alias == "Member")
                    {
                        var Email = memberItem.Email;
                        var AdditionalEmail = memberItem.GetValue<string>("additionalEmail");
                        var IsExist = _memberService.GetByEmail(AdditionalEmail);
                        if ((string.IsNullOrWhiteSpace(Email.ToLower()) == string.IsNullOrWhiteSpace(AdditionalEmail.ToLower())) || IsExist!=null)
                        {
                            e.Cancel = true;                    
                            e.Messages.Add(new EventMessage("Invalid email", "You can not add already existing email...", EventMessageType.Success));
    
                }
           }
       }
    }
    

    Please help to find a solution for this

    Thank You

Please Sign in or register to post replies

Write your reply to:

Draft