Manage Learn to apply best practices and optimize your operations.

Validating Web forms

Warn a user when a Web form fails validation.

As most people reading this will know, the simplest way to warn a user that their form failed validation is with an @Failure("..") statement in the validation event of all required fields. From the user's point of view the main problem with this is that they only get to see one warning at a time, which means that if several fields have failed validation the user may have to re-submit several times before the form is accepted (saved).

JavaScript validation can avoid that problem but some Notes developer's don't know JavaScript well, a few Web clients don't do JavaScript and many JavaScript warning messages are not very pretty.

One way to get all validation warnings together and display them attractively is to use an agent launched by the WebQuerySave event, another way is to bunch all validation in a single field validation event with formula language.

A formula like the one below in the validation event of the last editable field on the form will trap failures and display them together in a helpful way. Most of the formula deals with setting up links for the user to follow if they decide to abandon their editing, you may want to limit this option. Validation is done towards the end of the formula using the temporary variable 'err'. A validation failure produces something like this:

Sorry but your calendar entry can't be saved!

There were validation errors:
o your calendar entry has no subject
o start time is not valid, use hh:mm
o end time should be after start time

Click here to return to your edits then make the changes and re-submit. If your message is empty when you return you probably have your browser set to check for newer versions of pages on every visit, checking each time you start your browser should be adequate (and it will be quicker).
Click one of the links below if you want to abandon your message edits.
----------------------------------------------------------------------
by Topic | by Author | by Category | by Date | Noticeboard | Help


REM "for the validation event of the last editable field on the form";

PreviousDoc := "Click here to <A href="javascript: history.back()">" + "return to your edits</A> then make the changes and re-submit. If your message is empty when you return you probably have your browser set to check for newer versions of pages on every visit, checking each time you start your browser should be adequate (and it will be quicker).<br>" + "Click one of the links below if you want to abandon your message edits<br><hr>";

db:="/"+@ReplaceSubstring(@Subset(@DbName;-1);"\":" ";"/":"+")+"/";

ByTopic := "<a href=""+db+"ByTopic?OpenView">by Topic</a> | ";
ByAuthor := "<a href=""+db+"ByAuthor?OpenView">by Author</a> | ";
ByCategory := "<a href=""+db+"ByCategory?OpenView">by Category</a> | ";
ByDate := "<a href=""+db+"ByDate?OpenView">by Date</a> | ";
Noticebrd := "<a href=""+db+"Noticeboard?OpenView">Noticeboard</a> | ";
Help := "<a href=""+db+"HowToUse">Help</a>";

FieldValidation:=
 PreviousDoc+ByTopic+ByAuthor+ByCategory+ByDate+Noticebrd+Help;


app:=AppointmentType;
sdt:=@TextToTime(StartDate);
edt:=@If(app="2";@TextToTime(EndDate);"");

err:=
@If(Subject="";"your calendar entry has no subject~";"")+
@If(!@IsTime(sdt);"start date is not valid, use dd/mm/yyyy~";"")+
@If(app="2" & !@IsTime(edt);"end date is not valid, use dd/mm/yyyy~";"")+
@If(app="2" & (edt<sdt);"end date should be after start date~";"")+
@If(app="0":"3" & @TextToTime(EndTime)<=@TextToTime(StartTime);"end time
should be after start time~";"");

@If(err="";@Success;
@Failure("<FONT SIZE="-1" COLOR="C60031" FACE="VERDANA,ARIAL,HELVETICA">"
+"<b>Sorry but your calendar entry can't be saved!
<br><br>There were validation errors:</b><ul>"
+@Implode("<li>"+@Explode(err;"~";@False)+"</li>";"")
+"</ul></FONT>"
+"<FONT SIZE="-1"
FACE="VERDANA,ARIAL,HELVETICA">"+FieldValidation+"</FONT>"))

Dig Deeper on Domino Resources - Part 7

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close