Validating fields before submission

I’m pretty new to Domino Designer and pretty much all programming for that matter. I am creating a simple (for most) database for a user. When the user clicks on the Submit Action button, I am trying to validate that all the fields are populated before submission. If the fields do have items in them, then I would like a box saying Success or something and then have the document saved, closed and an email to be sent to someone. I have been trying to use the @if statement, but this just seems like a lot of work. Is there an easier way of going about this? Here is the code that is in the Submit button:

@If (

 @IsNull (Extension); @Prompt ([Ok];"Error";"Please Enter an Entension Number");

 @IsNull (Subject); @Prompt ([Ok];"Error";"Please Enter a Subject"); 

 @IsNull (Attendees); @Prompt ([Ok];"Error";"Please Enter the Number of Attendees");

 @IsNull (DateBegin); @Prompt ([Ok];"Error";"Please Enter the Date Needed");

 @IsNull (RoomPreference); @Prompt ([Ok];"Error";"Please Select a Room");

 @IsNull (RoomSetup); @Prompt ([Ok];"Error";"Please Select the Setup Type needed for the Room");

 @IsNull (StartTime); @Prompt ([Ok];"Error";"Please Indicate a Start Time"); 

 @IsNull (EndTime); @Prompt ([Ok];"Error";"Please Indicate an End Time");



 @Prompt ([Ok];"Success"; "Success");

 @MailSend("John Doe/Acme Company";"";"";"You have a request for a room";"";"Comments");

 @Do(@Command([FileSave]); @Command([FileCloseWindow])))

This does work up to a point. It will validate everything and if everything is correct. I get the prompt of Success, but the @mailsend and @do statement aren’t working. If this because the @Prompt ([Ok];“Success”; “Success”) statement is the Else Action portion of the @if statment?

Thanks for the help.

Subject: Validating fields before submission

A few things.

First, welcome to Notes and the forum, this is a great place.

Second - edit your post and put the stuff in an easier to read format (and you can do this in your code to keep it easy for you to read it). For example:

@If(

condition1=whatever;action1;action2;

condition2=whatever;action3;action3)

Build it so it’s easy to see how stuff is nested and related.

Third - you probably have the code exiting somewhere so it’s tied into your if/the/do stuff.

Last - you have a couple of other options for validating input.

Each field has a validation formula. The advantage is that you can use @IsValid in your save button to test the fields all at once. The disadvantage is you’ll get a bunch of popups for each field and will annoy your user. Of course, this is basically what you’re doing in your code so you’ll annoy them too.

Or…

In your save button do something like:

Assume Field1 is for company name and Field2 is for phone number.

Flag1 := @If(Field1 = “”; “Company Name”;“”);

Flag2 := @If(Field2 = “”; “Phone Number”;“”);

Errors := @Trim(Flag1 : Flag2);

@If(Errors = “”;

@Success;

@Return(@Prompt([okcancellist];“Error”;“The following data is missing”;“”;Errors)));

Now they get a list of missing stuff and know exactly where to go and what to do.

Or…

Make it painfully clear what data is required to save the document - icons, color, anything.

Hide the save button until everything is present.

Provide them a ‘what am I missing’ button so if the flags aren’t clear enough you can list out all the missing stuff. Use a similar concept to the idea just before this one.

There are several blogs that provide some excellent UI design ideas - interface matters and escape velocity are great starting places - they’ll point you to even more.

Welcome and good programming.

Doug

Subject: RE: Validating fields before submission

Or, if you’re open to learning LotusScript, which is really pretty easy, you can just put some code in the QuerySave of the form that loops through all fields and checks for values. This way, you don’t have to code in all the field names to check, and you don’t have to change your code if you add fields later on.

In its simplest form, it would look like this:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

On Error Goto errhand

Dim doc As notesdocument

Dim errorStr As String



Set doc = source.document

errorStr = ""





Forall i In doc.items

	If i.Values(0) = "" Then

		errorStr = errorStr & i.Name & Chr(10) & Chr(13)  'the last part is just a line break

	End If

End Forall



If errorStr <> "" Then

	Msgbox "The following fields require values:" & Chr(10) & Chr(13) & errorStr

continue = false

else

continue = true

End If



Exit Sub

errhand:

Msgbox "QuerySave error at line " & Erl & ": " & Error

Exit Sub

End Sub

If you wanted to get complicated and exclude certain fields from the validation, you could set up an array of field names to exclude. Then when you’re running the loop, check to see if the field is a member of the array before dealing with it:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

On Error Goto errhand

Dim doc As notesdocument

Dim fieldArray(1 To 2) As String

Dim errorStr As String



Set doc = source.document

errorStr = ""

fieldArray(1) = "scriptDesc" 'scriptDesc and scriptCode are field names on my form

fieldArray(2) = "scriptCode"



Forall i In doc.items

	If Isnull(Arraygetindex(fieldArray,i.Name ) ) Then 'the field we're on is not in the to-be-excluded list

		If i.Values(0) = "" Then

			errorStr = errorStr & i.Name & Chr(10) & Chr(13)  'the last part is just a line break

		End If

	End If

End Forall



If errorStr <> "" Then

	Msgbox "The following fields require values:" & Chr(10) & Chr(13) & errorStr

End If



Exit Sub

errhand:

Msgbox "QuerySave error at line " & Erl & ": " & Error

Exit Sub

End Sub