Copied to clipboard

Flag this post as spam?

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


  • Ben Palmer 176 posts 842 karma points c-trib
    Sep 09, 2022 @ 17:40
    Ben Palmer
    0

    Umbraco Forms - Field Names Not Showing in Email Template (Razor)

    Hi,

    I have a form setup and have an email being sent using the default Umbraco email template.

    However, when the email comes through, the @field.Name isn't showing above the field values.

    I've updated to the latest version supporting 9 (9.5.1) and also tried 9.5.0 with no luck.

    If I use @field.Alias this works as expected.

    A screenshot of the email:

    enter image description here

    The template I'm using is:

    @foreach (var field in Model.Fields.Where(x => ignoreFields.Contains(x.FieldType) == false))
                            {
                                <h4 style="font-weight: 700; margin: 0; color: #000000;">@field.Name</h4>
    
                                <p style="margin-top: 0;">
                                    @switch (field.FieldType)
                                    {
                                        case "FieldType.FileUpload.cshtml":
                                            var uploadCount = 0;
                                            foreach (var fileUploadValue in field.GetValues())
                                            {
                                                if (fileUploadValue != null && !string.IsNullOrEmpty(fileUploadValue.ToString()))
                                                {
                                                    uploadCount++;
                                                }
                                            }
    
                                            if (uploadCount > 0)
                                            {
                                                <span>@uploadCount file@(uploadCount == 1 ? string.Empty : "s") uploaded</span>
                                            }
    
                                            break;
    
                                        case "FieldType.DatePicker.cshtml":
                                            var datePickerValue = field.GetValue();
                                            if (datePickerValue != null && !string.IsNullOrEmpty(datePickerValue.ToString()))
                                            {
                                                DateTime dt;
                                                var dateValid = DateTime.TryParse(datePickerValue != null ? datePickerValue.ToString() : string.Empty, out dt);
                                                var dateStr = dateValid ? dt.ToString("f") : "";
                                                @dateStr
                                            }
                                            break;
    
                                        default:
                                            var values = field.GetValues();
                                            if (values != null)
                                            {
                                                foreach (var value in values)
                                                {
                                                    if (value != null)
                                                    {
                                                        @(value is string ? value.ToString().ApplyPrevalueCaptions(field.Id, Model.PrevalueMaps) : value)<br />
                                                    }
                                                }
                                            }
                                            break;
                                    }
                                </p>
                            }
    

    Thanks,

    Ben

Please Sign in or register to post replies

Write your reply to:

Draft