Validation on fields on page before submitting data

I have a collection form with fields that has a submit button on it which works fine, but how do I force it to return to the previous page or display an error if the fields are left blank? There is a cancel button with an event of page navigation that returns to previous page, but I would like the submit button to validate and if the fields are blank to automatically return if possible.

Is there a javascript that can be used to accomplish this

Hi @pprecision,

We have a concept of Validations rules in Collection settings, which can be applied to any form, so that you can decide which fields needs to be filled as mandatory while filling the form.

You can create validation rules from there, and then you can bind those rules to the collection form.

Alternatively, you can use custom Javascript code if you want.

Thanks.

Thanks.

The collection validation rules are the better first step: mark the required fields and bind the rule to the form so the user gets an inline error and stays on the page with their data intact. Use custom JavaScript only for cases the rules cannot express, such as cross-field checks. I would avoid automatically navigating back on blank fields, because the user then cannot see which field failed validation; prevent submit, show the error, and let cancel remain the explicit navigation action.