Shailesh
Shailesh

Reputation: 544

WFFM 8.1 File Upload validation Control Customisation

I am using WFFM 8.1 rev. 160304 Update-2. I have to do below Customisation in File Upload validation Control :

For top two requirements I am referring the below URLs but it's not working .

https://sitecorejunkie.com/2014/04/06/restrict-certain-files-from-being-attached-to-web-forms-for-marketers-forms-in-sitecore/

https://jonathanrobbins.co.uk/2015/10/06/sitecore-marketplace-module-secure-file-upload/

Upvotes: 0

Views: 352

Answers (1)

Gatogordo
Gatogordo

Reputation: 2635

I have an upload field working with the some of your requirements (file size and extension). It should be extendable to include your others as well.

What we did was:

  1. Create a custom field that inherits from FileUploadField
  2. Add custom attributes to public override HttpPostedFileBase Value { get; set; }, e.g. [LimitAllowedExtensions][LimitFileSize]
  3. Create those custom attributes by overriding from DynamicValidationBase, e.g. public sealed class LimitAllowedExtensionsAttribute : DynamicValidationBase
  4. In those classes, override protected override ValidationResult ValidateFieldValue(IViewModel model, object value, ValidationContext validationContext) with the validation you want

Register your custom field in Sitecore and you're good to go. I'm not sure how to do the upload to a physical folder, you might want to look at the other functions in the FileUploadField (and maybe use a decompiler to check out the original code).

Wrote a blog post explaining this.

Upvotes: 2

Related Questions