SNTT adding http onto URL strings in Lotus Notes

The challenge was to have end users enter url’s (or uri’s) for content and have it presented as a link on the read only end part of the site. The problem is that means having “http” (or “https”) -which indicates Hypertext Transfer Protocol – appended to the string, if it was not supplied by the end user.

so in the Input Translational part of the editable field I used the following formula :

1
2
3
4
5
tempUrl := @ReplaceSubstring(@Trim(@ThisValue); @Char(0) : " "; "");
testUrl := @UpperCase(tempUrl );
@If(tempUrl  = "";@Return("");
@Begins(testUrl ;"HTTPS://") | @Begins(testUrl ;"HTTP://"); tempUrl ;
"http://"+tempUrl )

what’s going on here?
1) doing a quick stripping out of blank spaces
2) making a copy of that result which is all Upper case
3) if the result is a blank string retun a blank string and stop
4) test if the string starts with http or https already properly appended, if so the return the string
5) if not, then appended “http://” to string.

a couple of notes: a) All modern browsers assume “http://” so you don’t need to type that into the address bars, but for a anchor link href the “http” (or some other protocol) is required for external references. b) And “www.” is not required and any sensible web site will work with either “www.domainName” or “domainName”. indeed “www.” is not used for (and breaks) sub domains (“subDomain.domainName”)

of course a more interesting problem would be validating those url’s!

Leave a Reply