0

How we can send email with attached file, while clicking form submit button?

We are currently using Sitecore 9 Update 2 with SXA 1.7.2.

1

As an alternative, you can create a custom action "send email" based on: Send-E-mail-Action-to-Sitecore-9-Forms, add to action's editor dialog/view model link to media item. And when on action executing add to mail attachments linked media item.

| improve this answer | |
0

There is no functionality like that in your version of Sitecore, neither it is in latest Sitecore 9.1.

You have two options:

  1. Create your custom Field Type "FileUpload" inspiring by official documentation by Sitecore -> https://doc.sitecore.com/developers/91/sitecore-experience-management/en/walkthrough--creating-a-custom-rating-element-with-property-editor.html .
  2. Use code from Sitecore Forms Extensions github repository https://github.com/bartverdonck/Sitecore-Forms-Extensions and specifically this part -> https://github.com/bartverdonck/Sitecore-Forms-Extensions/tree/master/src/Feature/FormsExtensions/code/Fields/FileUpload.

    It should have really simple model:

    using System;
    using System.Globalization;
    using System.Web;
    using Feature.FormsExtensions.Business.FileUpload;
    using Sitecore;
    using Sitecore.Data.Items;
    using Sitecore.ExperienceForms.Mvc.Models.Validation;
    
    namespace Feature.FormsExtensions.Fields.FileUpload
    {
        [Serializable]
        public class FileUploadModel : ValueNotValidatedInputViewModel<IStoredFile>
        {
            [NonSerialized]
            private HttpPostedFileBase file;
            private const string AllowedContentTypesParam = "Allowed Content Types";
            private const string MaxFileSizeParam = "Max File Size";
    
            [DynamicRequired]
            [DynamicValidation]
            public virtual HttpPostedFileBase File
            {
                get => file;
                set => file = value;
            }
    
            public string AllowedContentTypes { get; set; }
            public int MaxFileSize { get; set; }
    
            protected override void InitItemProperties(Item item)
            {
                base.InitItemProperties(item);
               AllowedContentTypes = StringUtil.GetString(item.Fields[AllowedContentTypesParam]);
               MaxFileSize = MainUtil.GetInt(item.Fields[MaxFileSizeParam]?.Value, 0);
            }
    
            protected override void UpdateItemFields(Item item)
            {
                base.UpdateItemFields(item);
                item.Fields[AllowedContentTypesParam]?.SetValue(AllowedContentTypes, true); 
                item.Fields[MaxFileSizeParam]?.SetValue(MaxFileSize.ToString(CultureInfo.InvariantCulture),true);
            }
        }
    }
    
| improve this answer | |
  • While submitting the submit button, i'm getting null value for the File – PKH Jan 17 '19 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.