InfoPath Submit Options and Form Validation

An InfoPath button’s action may be configured as either a submit button or as “rules and custom code”. The form may be submitted via either mechanism, but there is a subtle difference for how validation (like ensuring that the user has completed all required fields, etc) is done depending on which option you choose. Specifically, if the button is set to be a submit button, the validation will be checked before the submit rules are processed. If the button is set to be “rules and custom code”, the rules will fire in order and the form’s validation will only be checked when it reaches the submit action.

This is significant. It means the difference between processing rules any time the user clicks the button, whether or not the form is filled in correctly, or only processing the rules if the validation checks out ok.

Since the above is a little confusing, here’s an example:

Consider the following form:

In the above are form, there are two submit buttons. Both submit the form. The first button has its action set to submit. The second has its action set to rules and custom code.

The following are the submit options for the form:

 

Note that it is using rules for the submit.

And here are the rules:

 

 

The first button is simply configured as a submit button:

 

 

And, the following dialog is the properties of the second button:

Note that the action is set to rules and custom code.

And, the following are the rules configured for that button:

Note that the above rules are the same for both buttons. But again one button’s action is set to submit and the rules are configured through the submit. The other button has its actions set to rules and custom code. Again, even though both buttons are processing the same rules due to the difference in actions, but there’ll be a difference in how the form is validated. Or rather, when the form is validated.

 

The following shows what happens when a text values input into the number fields, and the submit button is clicked that has its action set to submit. Again, the submit rules specify that the text field should have a value the ABC, and then the form should be submitted.

 

Note in the above, the text field is still empty. Even though the rules said to set the text field and then submit, since the rules have been processed as part of the submit options the validation was checked before attempting to execute the rules.

The following shows what happens when a text values input into the number fields, and the submit button is clicked that has its action set to rules and custom code. Again, the submit rules specify that the text field should have a value the ABC, and then the form should be submitted.

 

Note that in the above, the text field now has a value. Since the options were carried out as simply part of the button’s rules, the validation did not occur until the submit action was triggered. Which in this case was after the text field was set to ABC.

Enjoy.

 

 

 

 

 

 

Advertisements

4 thoughts on “InfoPath Submit Options and Form Validation

  1. Hameer

    Wonderful article Mike.
    I banged my head against this one for quite some time.

    Just wondering though, can we have multiple submit buttons with different rules for each.
    Thing is, I want to get the same behavior (i.e. I want vaious rules to be executed only if the validation is successful) but I have different buttons meant to perform different actions and each of them can have their own rules.

    Any early reply would be most helpful.

    Reply
    1. Mike G Post author

      You can have multiple buttons that submit, but you are limited to one definition of what to do when the form is submitted. In fact, when you set up the form submission options, a “submit” command is added to the file menu and to the toolbar. So, when you add a submit button, it will call the same procedures as the others. Of course, you can submit through rules and deal with the differences in validation, as the blog post describes. You can also submit through custom code…

      Reply
    1. Mike G Post author

      You want something a little more custom than a red border around the textbox? Unfortunately, we don’t have many options that I know of. If a field is set to numeric (whole number) and the user types in an invalid entry, the box will be red and the message will be “Only integers allowed”. You can customize that message by specifying a value for the “screen tip” property (text box properties –> advanced tab –> screen tip. Note that if you do this, your custom message will display when the user hovers over the textbox whether or not there’s an error. Otherwise, if you specify validation rules, you can customize the messages for each validation rule.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s