I have a form that must be validated both on the web and on the client. I have chosen to use an agent that is called from the WebQuerySave event for the web, and call it from QuerySave for the client. Everything is working great except for one thing I would like to do.
I like to let the user fill out the form completely and then submit it for validation, and then present them with a complete list of errors. So during validation I check for errors and keep a list then present a dialog box with the list. Works fine on the client, but in the web it seems I cannot access the field on the form that contains the errors to pop up in the dialog box.
Is there a way to do this?
See code below:
'Submitted By Name cannot be blank.
If doc.SubmittedByName(0) = "" Then
errors = True
errString = errString & "Submitted By Name cannot be blank.¥:"
End If
'Validation is passed
If errors = False Then
If result(0) = "Web" Then
doc.saveoptions = "1"
Else
doc.saveoptions = "1"
End If
End If
If errors = True Then
If result(0) = "Web" Then
doc.errors = errString
Print "<HTML><BODY><SCRIPT LANGUAGE=JavaScript>window.alert(document.forms[0].errors.value);history.go(-1);</SCRIPT></HTML>"
Else
doc.errString = errString
End If
End If
Subject: Multiple lines in alert in WebQuerySave
Bryan,
When the html contained in your Print statement gets rendered to the user’s web browser, there is no document.forms[0] object there anymore. Try this instead:
Print “”
Subject: RE: Multiple lines in alert in WebQuerySave
The whole hostory.go(-1) part is not really needed, if you use a Domino generated submit button (that is, one containing @Command([FileSave]).
Under this precondition simply setting SaveOptions to “0” in case the validation fails is really all you need to do. Also, displaying validation error messages in a pop-up window is not considered very elegant today: As soon as the user clicks OK, all hints concerning unacceptable inputs are gone. One alternative (that I like to use) is to simply have the WQS agent put the error messages into a multivalue field and remove that item, if the document passes validation on next submit.
Using a very similar technique, you could also place error messages right next to each field, that caused an error.
And one more hint: If you still prefer to put out some HTML using print statements, either omit the HTML and BODY tags, or make them valid HTML. If you omit them, Domino will automatically generate them for you, even adding a DOCTYPE line. The only thing Domino forgets is to include a TITLE tag, which is mandatory in HTML 4. HTML and BODY tags on the other hand are optional.