Copied to clipboard

Flag this post as spam?

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


  • Shawn Calvert 31 posts 195 karma points
    Aug 15, 2018 @ 05:15
    Shawn Calvert
    0

    Umbraco Forms: Error when using member data

    Hello,

    I'm trying to pull member properties into an Umbraco Form field, but it's throwing an error that keeps the form from rendering.

    The member property:

    enter image description here

    used as a prevalue in a hidden field:

    enter image description here

    The error:

    enter image description here

    It seems to be a similar issue to this thread, but it looks like it was fixed:

    https://our.umbraco.com/forum/umbraco-forms/80165-use-member-data-in-forms

    Does anyone have an idea what would cause this or a fix?

    thank you

  • Shawn Calvert 31 posts 195 karma points
    Aug 16, 2018 @ 20:36
    Shawn Calvert
    0

    ... still trying to figure out what's causing this error in Umbraco Forms. Looking in the logs, it is throwing an error of "An item with the same key has already been added."

    enter image description here

    I've seen a few threads here where a similar issue has popped up elsewhere in Umbraco, but this seems to be specific to pulling member info into forms. I've tried:

    • using other, most definitely not repeated, member properties
    • embedding the form on pages that don't pull in member data, or have
      permissions set
    • stripping down the form and workflow

    ... but no go. Maybe all of the member data is being pulled in another way, but I'm not sure how to find the conflict.

    thanks

  • Shawn Calvert 31 posts 195 karma points
    Aug 21, 2018 @ 16:47
    Shawn Calvert
    0

    I couldn't figure out where the member data was in conflict, or if it was a bug (or related to analytics) ... so I did the javascript workaround. For the possible benefit of other 'implementors' trying to figure this out, this is how it worked -- I have no doubt this could be handled better, if anyone wants to add any comments.

    in the template, call in your member info

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Article>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @using Umbraco.Web.Models;
    @using Umbraco.Web.Security;
    
    @{
        Layout = "Master.cshtml";
        var loginStatusModel = Members.GetCurrentLoginStatus();
        var membershipHelper = new MembershipHelper(UmbracoContext.Current);
        var currentUser = Membership.GetUser();
        var currentMember = currentUser != null ? membershipHelper.GetById((int) currentUser.ProviderUserKey) : null;
    }
    

    I wanted to create a share link that would pop the form in a modal, ask the member for the email, then send a link to the article with an excerpt, and a note of "member name has shared an article ..."

                var currentFirstName = currentMember.GetPropertyValue("firstName");
                var currentLastName = currentMember.GetPropertyValue("lastName");
                var contentSnippet = Umbraco.Truncate(library.StripHtml(Model.Content.GetPropertyValue<string>("articleContent")), 250, true);
                var currentMemberName = (currentFirstName + " " + currentLastName); 
    
                <input id='membernameorigin' name='member-name' type='hidden' value='@currentMemberName'>
                <input id='snippetorigin' name='member-snippet'  type='hidden' value='@contentSnippet'>
    
                { Html.RenderPartial("SiteLayout/_articleshare"); } 
    

    then move the values into the Umbraco form fields

    <script>
        var membernameorigin = $('#membernameorigin');
        var membernamecopy = $('#03450430-3433-89ef-bab2-fb30b46ee564');
        var snippetorigin = $('#snippetorigin');
        var snippetcopy = $('#e26d32c9-2183-4c34-cc66-6545hbe87dc45');
        membernamecopy.val(membernameorigin.val());
        snippetcopy.val(snippetorigin.val());
    </script>
    

    note, if you are using bootstrap modals in partial, you might need to move it down the dom

    $(function(){
        $('body.article #modalShare').appendTo("body") 
    });
    

    'membernamecopy' passes a value to a hidden field (in Umbraco Forms back office) with the alias "memberSendName", so you can then pass that value into a workflow using a 'magic string', e.g. add to the subject line:

    {memberSendName} has shared an article with you
    

    if you are using the form in a modal, the submission needs to be done via ajax, or your modal just closes, and is replaced with your 'thank you' message when reopened again on the same page.

Please Sign in or register to post replies

Write your reply to:

Draft