Submitted Form's Sequence Of Events
The sequence of events for form submission are:
- User presses submit button
- Data is stored in the pending queue
- if this fails then "Error storing form data in pre-submission queue." is displayed to the user via BMP.alert() and the process terminates
- The form data is validated per definition
- if this fails, then validation errors are displayed at the bottom of the form, and the process terminates
- The form data is submitted to the server
- if offline, then the process terminates
- if there is a transmission error / timeout, then the process terminates
- The server validates the form per definition
- if there were any validation errors, an error status code is sent back to the device and the process terminates
- "before" Forms MADL executes
- if there were any errors or Forms MADL populated the $errors variable, then an error status code is sent back to the device and the process terminates
- if BlinkNow or DB Connector are configured and $donotsave is falsey, then tuple is injected in DB, and "after" Forms MADL executes
- If there was a DB error, or Forms MADL populated the $errors variable, then an error status code is sent back to the device and the process terminates
- otherwise a success message is sent back
- If the device receives a success status code AND a non-empty message, then the pending record is removed and the success is displayed to the user
- otherwise an error message is displayed to the user
There are only 2 places in the entire codebase that remove data from the pending queue:
- step 9 in the above submission process
- the clear button on the pending queue listing
Best practice for Forms MADL would be to establish a temporary error in the $errors array on the first line, and only clear out that temporary error when the rest of the custom code is happy and completed.