I’m after the definitive approach for doing server side validation of new unsaved documents on the web.
Perhaps best to give the scenario first. Have a public “User Registration” form where anonymous users enter their details, including a username and password they invent.
The validation has to check that the database doesn’t contain a duplicate of their username.
A client side validation routine is not suitable, as there is no javascript equivalent for @DbLookup (not for both Netscape and IE that is) and having a computed field/computed text to retrieve all existing names on open is not suitable (there is more than 64KB of returned data; security concerns over showing all usernames in page source).
One option considered was to set SaveOptions and handle validation in WebQuerySave. The problem with this is that the form disappears on submit (regardless of whether it fails or passes validation) so you need some means of redisplaying the (unsaved) form contents so that the user may make the necessary corrections.
As I said, the form contains passwords, so use of the query string to achieve this is out.
Despite trawling this forum, I can’t find a definitive rock-solid method of doing this sort of thing. I’m after the simplest and most robust solution.
Subject: Server side validation on web - found a way
Validation is done “server side” via simple formulas in the WebQuerySave event. You check any fields using whatever formulas are needed. The formula sets a SaveOptions field to “1” where validation is passed, or “0” otherwise. A numeric field “hasError” is set to 1 where errors were found, or 0 otherwise. The formula also builds a text field called for example “errors” that contains a description of any errors found (your formula should build up this field for all errors).
WebQuerySave is triggered by a button with the formula: @Command([FileSave]); @If(hasError; “”; @Command([CloseWindow]))
Where no errors are found, the above formula saves and closes the document, and only then triggers the formula in the $$Return field.
Where errors are found, the form with all of its entered values still present is displayed back to the user. It also contains the updated field values for “hasError” and “errors”, so these may be intercepted OnLoad by javascript, or displayed on the form as computed text.
The beauty of it is that you can use @Formulas with @Dblookups at the time of validation. There are also ways to bypass client-side javascript validation, that can’t bypass this.