Copied to clipboard

Flag this post as spam?

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


  • Peter Cort Larsen 420 posts 1017 karma points
    Jan 10, 2024 @ 08:56
    Peter Cort Larsen
    0

    umbraco forms add extra data to saved entry

    Hi,

    We need add extra data to each saved form entry. We must collect tracking data from our affiliates.

    I can create hidden form fields thru C# and populate their values from JS.

    But how do i add the data to each saved form entry, without having to add the field types on each created form in the backoffice?

    I tried looking into RecordSavingNotification, but cant figure out how to use this.

  • Peter Cort Larsen 420 posts 1017 karma points
    1 week ago
    Peter Cort Larsen
    0

    I tried this approach on form.cshtml for a theme. Unfortunately thats dosnt add the field to the form. It adds it on the frontend.

    What i actually would like is to add my fields to each saved record. Maybe i need to do it someplace else. Can anyone point me in the right direction?

    Its Umbraco 10.

    var ipGuid = Guid.NewGuid().ToString();
    FieldViewModel mm = new FieldViewModel()
            {
                Alias = ipGuid.ToString(),
                FieldTypeName = "HiddenField",
                Id = ipGuid,
                Mandatory = false,
                PlaceholderText = "MYIP",
                Name = ipGuid,
                Validate = false,
                FormId = Model.FormId,
                Caption = "MYIP",
                FieldsetId = Guid.Parse(Model.CurrentPage.Fieldsets[0].Id),
                Values = new List<string>() { "TEST VAL" },
                FieldType = new Umbraco.Forms.Core.Providers.FieldTypes.HiddenField(),
            };
    
    Model.Pages.First().Fieldsets.First().Containers.First().Fields.Add(mm);
    
Please Sign in or register to post replies

Write your reply to:

Draft