...
If validation in successful, the web controller then calls the FormSubmissionController handleFormSubmission(FormEntrySession, HttpServletRequest) method. Again, the FormSubmissionController iterates through all the FormSubmissionControllerActions, this time calling their handleFormSubmissionhandleSubmission(FormEntrySession, HttpServletRequest) methods to handle the submission of the individual elements in the form.
...
If your module instantiates a Spring bean that implements org.openmrs.module.htmlformentry.velocity.VelocityContextContentProvider then your bean's populateContext() method will be called each time a new HTML Form is opened (for entry, view, or edit). (Since HTML Form Entry 1.11)
See an example from the Kenya EMR module on github.