Home > Domino Tips > Developer > LotusScript > Friendlier Web Validation
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Friendlier Web Validation


Mark Bryson
11.22.2000
Rating: -3.25- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


You can validate forms on the web using Notes @Formula language in field validation formula or Javascript in field events or the form onSubmit event.

Using individual field validation checks on the web may discourage users because on submission they only get the failure message from the first field to fail its validation, they may have to make repeated changes and submit a form several times before they get it all right. Repeated failed submissions also involve unnecessary network and server traffic and can be slow.

Javascript validation is better in that it all happens at the client and can be made to present all validation failure messages at once if done via the form onSubmit event. However Javascript adds to the size of the web form, is not standard on all browsers and can be difficult to debug, even more so than Notes formula language!

There is a 'third way' that uses @Formula validation but presents all failure messages at once and displays them attractively too! You can do it all in one field but I prefer to use two.



Code

Add a hidden, computed-for-display field at the top of the form and call it 'ValidationMsg', it can be a shared field if you prefer. The contents of the field should be something like:

"Your document can't be saved"
+ "Sorry

"
+ "Click go back"
+ " then add the missing details and re-submit.

"
+ "Click here if you want to abandon your edits"

In the last line 'db' is the name of another computed-for-display field above the 'ValidationMsg' field in the form. 'db' should evaluate to a URL suitable for users to 'jump back into' the web site if they give up their submission, I just re-open the database with the formula:

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

This 'ValidationMsg' field can be used with validation formula in each field simply by adding the field name to the end of your @Failure string ... but if you want to show all validation failures together, remove validation formula from all editable fields in the form and add another field at the bottom of the form, make it a hidden, editable field and call it 'ValidationCheck'.

This 'ValidationCheck' field is where all the validation happens so you might need lots of @Formula language! The example below does two things really. First, it gets rid of some editable fields used in the form but which don't need to be saved. Second, it selectively adds failure messages to an initial string (x). If the final message (err) is the same as it was at the beginning (if err = x), then we know there are no validation failures and the submission can succeed. If there are errors we add the ValidationMsg text to our error messages, along with some HTML to make it look nice and present it all to the user. The 'ValidationCheck' field Input Validation event might contain a formula like this:

FIELD Bannerweeks:=@DeleteField;
FIELD Bannerdays:=@DeleteField;
FIELD Query_String:=@DeleteField;
FIELD FileQuotaCheck:=@DeleteField;
FIELD PWeb:=@If(PWeb="";@DeleteField;Pweb);
FIELD Phone:=@If(Phone="";@DeleteField;Phone);

files:=@If(@Attachments>0;@Integer(@Sum(@AttachmentLengths)/1024);0);
namereq:=@If(ShowName="Y"|@IsNotMember("[editor]";@UserRoles);@True;@False);

x:="You need to enter

    ";

    err:=x+
    @If(namereq & !(@Length(Name)>7 & @Contains(Name;" "));"

  • contributor's full name
  • ";"")+
    @If(namereq & !(@ValidateInternetAddress([Address821];Email)="" | Phone!="");
    "
  • a valid email address ("+
    @ValidateInternetAddress([Address821];Email)+") or phone number
  • ";"")+
    @If(@Length(Subject)>7; ""; "
  • a longer subject
  • ")+
    @If(@Length(@Abstract([TextOnly];99;"";"Body"))>20;"";"
  • more text
  • ")+
    @If(@Attachments>1;"
  • just one attached file per message
  • ";"")+
    @If((files>50);"
  • your attached file is too big ("+@Text(files)+"K)
  • ";"");

    @If(err=x; @Success;
    @Failure(
    ""+
    err+"

"+
""+ValidationMsg+"")
)


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
LotusScript
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts