InfoPath - How can I submit a form with validation errors?

This question has been put to me a couple of times so I thought I'd share my findings. It's not that uncommon a scenario; perhaps you want users to be able to submit a partially completed form or perhaps there are multiple roles involved in the completion of the form and once I've done my but I submit it for someone else to continue. The problem is, InfoPath wont let you submit the form with validation errors (eg blank fields). What can you do?

  • Add some code behind the “submit” button that clears the errors collection before invoking Submit() – this will allow the form to be submitted even though the data wont validate. You can of course check the errors collection before clearing it to make sure there’s nothing unexpected in there.
  • Modify the validation expressions on the form to include an additional parameter which you set in your “submit” button code. Eg a parameter called “IgnoreValidation”. Validation tests then become something like “TextBox is blank AND IgnoreValidation = FALSE”. Set the value of IgnoreValidation to TRUE in your “submit” code to allow submission without validation (and remember to set it back again to re-enable validation).

An elegant variation on the above is to employ the concept of user roles to check whether a particular validation rule should apply. You create a node in your data source for the current user's role and check that node in the data validation for each field to determine whether or not a particular rule should apply to this role. (eg something like: [field1 is blank] AND [userRole is equal to "employee"])

tags: infopath