This is a migrated thread and some comments may be shown as answers.

Validation in Sitefinity fileupload form widget

4 Answers 236 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Aidan
Top achievements
Rank 1
Aidan asked on 06 Oct 2014, 03:15 PM
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

4 Answers, 1 is accepted

Sort by
0
Ivan D. Dimitrov
Telerik team
answered on 08 Oct 2014, 11:38 AM
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
 
0
Aidan
Top achievements
Rank 1
answered on 14 Oct 2014, 07:39 AM
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
0
Boyko Karadzhov
Telerik team
answered on 16 Oct 2014, 08:33 AM
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
 
0
Aidan
Top achievements
Rank 1
answered on 19 Nov 2014, 03:02 PM
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
Tags
Upload
Asked by
Aidan
Top achievements
Rank 1
Answers by
Ivan D. Dimitrov
Telerik team
Aidan
Top achievements
Rank 1
Boyko Karadzhov
Telerik team
Share this question
or