FounderStartup's avatar

What is the best way to validate a huge form with 10 image uploads ?

I have a project where I have a form with 10 image uploads and 15 fields.

The user may find it difficult to complete the form in a single sitting. So I am trying to give him/her a SAVE button on the first attempt. After that he/she can update the form ( in as many attempts as he/she may wish ). Finally there is a button for "FINAL SUBMISSION". But how I will do the complete validations of all the fields ?

0 likes
8 replies
jorgensolli's avatar

Introduce a is_draft column to wherever you are storing the form. For the validation, you can specify what fields are required when submitting the form like this

[
	...
	'some_field' => 'required_if:is_draft,false'
	...
]

Read more here https://laravel.com/docs/9.x/validation#rule-required-if

Also, make sure the form is only submittable if it's in a draft state.

FounderStartup's avatar

@jorgen solli

Thanks for your time. But kindly elaborate a bit. I am not doing any validations during first SAVE and during UPDATES. I want ti validate only when the user clicks FINAL SUBMISSION button. So how I will validate when the update form is having values from the already stored values.

Tray2's avatar

This sounds very strange to me.

Are you showing the old values in each field if the user has made any mistakes in the form?

Add requiered to all the fields that are required in your html form, that way the user can't submit before everything is filled in properly.

Change the file input so that the user can select multiple images at once instead of having 10 different file inputs.

1 like
FounderStartup's avatar

@Tray2

The user may find it difficult to complete the form in a single sitting. So I am trying to give him/her a SAVE button on the first attempt. After that he/she can update the form ( in as many attempts as he/she may wish ). Finally there is a button for "FINAL SUBMISSION".

This is what I want to do. Just looking for a better solution. Images cannot be uploaded at one go as they all are for different fields and some are optional depending on a condition. Its actually an application for for students.

My issue is that how will I validate the fields at the time of FINAL SUBMISSION.

I know I can make a form and do all the validations at one go but the student will find it difficult to upload so many documents at one go. That's the whole purpose.

Snapey's avatar
Snapey
Best Answer
Level 122

@FounderStartup you cannot validate files at final submission since you must store them when submitted ( and validate at that time) so for these, that are required, you are going to need some additional state that tells you that attachment 3 has been validated and stored

You are probably going to need a complete draft submission model that you can allow the student to start to complete, recording each field as it is posted, with nothing required. Then when the final submission occurs you will need to check that you have all required fields

1 like
FounderStartup's avatar

@Snapey Thanks for understand the whole issue :). Is it a better idea to break the form in 3-4 parts and every part has to be submitted with complete validations ?

Snapey's avatar

@FounderStartup Well that just breaks it into small chunks that MUST be completed. It does not match your original requirement.

1 like
kokoshneta's avatar

@FounderStartup For the user, yes, that is generally a better idea. It’s easier and more overseeable to have five smaller forms to fill out than one massive form.

You should still have a Save functionality that allows the user to fill out some forms, then come back later and fill out the rest if they discover there’s a document they’re missing and have to obtain first, for example.

1 like

Please or to participate in this conversation.