Validation in Sitefinity fileupload form widget

5 posts, 0 answers
  1. Aidan
    Aidan avatar
    8 posts
    Member since:
    Sep 2013

    Posted 06 Oct 2014 Link to this post

    Hi,

    Not exactly sure if I'm in the right place, but here goes. I've included the default Sitefinity file upload widget into my form and have set it to be required. However, when I submit the form it doesn't validate whether a file has been selected or not. The unobtrusive validation is visible if you cancel when selecting a file but does not stop the form from being submitted. 

    Is this an error in the widget, of am I missing a different setting?

    Kind regards,

    Aidan Langelaan
    Fenêtre Internet Applicaties
  2. Ivan D. Dimitrov
    Admin
    Ivan D. Dimitrov avatar
    9 posts

    Posted 08 Oct 2014 Link to this post

    Hi Aidam,

    The make required setting is enough for the form to validate the field and not send a response when the upload field is empty. We have not had any similar problems reported regarding the file upload control. Can you please confirm that the control you are using is the regular out-of-the-box one and that the make required property is the only one you have altered. Also please specify which version of Sitefinity you are using as it is not clear based on the information in this thread.

    Regards,
    Ivan D. Dimitrov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Aidan
    Aidan avatar
    8 posts
    Member since:
    Sep 2013

    Posted 14 Oct 2014 in reply to Ivan D. Dimitrov Link to this post

    Hi Ivan,

    We are using Sitefinity version 7.1. For the form we have built a custom form handler. We have noticed we don't make use of client-side validation, only server side. Once the form is posted server side we check if all fields are valid. The Upload widget is apparently always valid, while a textbox that's required and empty is not valid. 

    We have checked this behavior against a standard Sitefinity form handler and can see Sitefinity does use client-side validation. Could you explain why the Upload widget is always server-side validated as positive?

    Regards, 

    Aidan Langelaan
    Fenêtre
  5. Boyko Karadzhov
    Admin
    Boyko Karadzhov avatar
    1 posts

    Posted 16 Oct 2014 Link to this post

    Hello Aidan,

    I can confirm the the FormFileUpload file does not check for Required on the server side. I have logged a public issue for it. Click here to view it.

    Until the issue is addressed by our team you can do the validation on an event like this:
    protected void Application_Start(object sender, EventArgs e)
    {
        Bootstrapper.Initialized += Bootstrapper_Initialized;
    }
     
    void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
    {
        if (e.CommandName == "Bootstrapped")
        {
            EventHub.Subscribe<IFormFieldValidatingEvent>(FormFileUploadFieldValidation);
        }
    }
     
    private void FormFileUploadFieldValidation(IFormFieldValidatingEvent @event)
    {
        var fileUploadField = @event.FormFieldControl as FieldControl;
        if (fileUploadField != null && fileUploadField.GetType().Name == "FormFileUpload")
        {
            var value = fileUploadField.Value as UploadedFileCollection;
            if (fileUploadField.Validator.Required)
            {
                if (value == null || value.Count == 0)
                    throw new ValidationException();
            }
        }
    }

    This should be placed in Global.asax.

    Regards,
    Boyko Karadzhov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  6. Aidan
    Aidan avatar
    8 posts
    Member since:
    Sep 2013

    Posted 19 Nov 2014 in reply to Ivan D. Dimitrov Link to this post

    Hi Ivan,

    Thank you for your reply and sorry for this late reply. We figured out it was down to our custom formhandler, this prevented the clientside validation from functioning. Yet this still means there is no server-side validation whatsoever for validating form uploads. Besides that, if the user chooses to 'add another' file, the field is automatically validated as correct if the first file upload field is filled in. The extra fields aren't validated. These observations were made in Sitefinity 7.1.

    Regards,

    Aidan Langelaan
    Fenêtre Internet Applicaties
Back to Top
UI for ASP.NET MVC is VS 2017 Ready