Copied to clipboard

Flag this post as spam?

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


  • Heather Floyd 531 posts 787 karma points MVP 2x c-trib
    Nov 08, 2016 @ 19:46
    Heather Floyd
    0

    Custom FieldType in Umbraco Forms : Setting properties always NULL

    I have created a custom fieldtype for Umbraco Forms based on the FileUpload fieldtype which will place the uploaded item into the Media section, so it can be automatically linked to a content node created by the submitted form data.

    I have defined some settings, which I can see in the Umbraco Forms editor, but in my code file, the properties are always NULL.

    If I debug and look at "this.Settings()" - I see the custom Settings listed.

    Is my configuration incorrect?

    Simplified code:

    namespace MySite.Forms.FieldTypes
    {
        using System;
        using System.IO;
        using System.Drawing;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using Umbraco.Core;
        using Umbraco.Core.Models;
        using Umbraco.Core.IO;
        using Umbraco.Core.Logging;
        using Umbraco.Forms.Core;
        using Umbraco.Web;
    
        public class MediaUpload : Umbraco.Forms.Core.Providers.FieldTypes.FileUpload
        {
            const int ImageMediaTypeId = 1032;
    
            [Umbraco.Forms.Core.Attributes.Setting("Allowed file extensions",
                 description = "Allowed file extensions (CSV)",
                 alias = "AllowedExtensions")]
            public string AllowedExtensions { get; set; }
    
            [Umbraco.Forms.Core.Attributes.Setting("Media Parent ID",
                 description = "ID of the parent where the media will be saved",
                 alias = "MediaParentId")]
            public string MediaParentId { get; set; }
    
            public MediaUpload()
            {
                //Provider
                this.Id = new Guid("84f24c36-103d-4161-b2ec-058e57e315f2");
                this.Name = "Media Upload";
                this.Description = "Upload file to Umbraco Media Section";
    
                //FieldType
                this.Icon = "icon-cloud-upload";
                this.DataType = FieldDataType.Integer;
    
                var settings = this.Settings(); //<---This shows the settings when checked...
                var test = settings.Count;
            }
    
    
            public override IEnumerable<object> ProcessSubmittedValue(Umbraco.Forms.Core.Field AssociatedField, System.Collections.Generic.IEnumerable<object> Values, System.Web.HttpContextBase HttpContext)
            {
                List<Object> vals = new List<object>();
    
                var parentId = this.MediaParentId; //<--- This is always NULL
    
                // Do stuff with submitted file...
    
                return vals;
            }
    
            public override IEnumerable<object> ConvertToRecord(Field field, IEnumerable<object> postedValues, HttpContextBase context)
            {
                List<Object> vals = new List<object>();
    
                //Do Stuff
    
                return vals;
            }
    
        }
    }
    

    Thanks! ~Heather

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies