Search

Assorted Linkage

Current Terror Alert Level

ClustrMap

« Design Catalog | Main| Server side cookies »

Using Lists to process dynamic forms

Category show-n-tell thursday
I've said it before and I'll say it again: LotusScript's List is under-utilized. Reference this previous post if you're curious about why I'm so infatuated with this datatype. For this week's installment of SnTT, however, I submit for your consideration my approach to handling dynamic web forms using a List.

When a standard Domino form is submitted by a browser, the value of each field defined on that form is conveniently written to the database. As we all know. But, as many of us have had occasion to bemoan, if additional fields are added in the HTML, Domino gets upset because there's no corresponding field defined in the design element. Others have described various approaches to circumventing this behavior, so I won't belabor that here. But what if you want to define an entire form dynamically? That's where a List comes in handy:
  1. Create an agent in the database that will process the form submission. In other words, the form doesn't have to exist in the same database, or even in Domino; this approach allows a Domino database to process submissions from any HTML form, regardless of how its content is generated. One application of this approach, however, would be to generate the form dynamically using Domino, i.e. a page element doing DbLookups or another agent that prints the form HTML to the browser.
  2. Set the form action to the URL of the form processing agent and the method to "post".
  3. Pull the field name and value pairs into a list in the form processing agent:
Dim sessCurrent As New NotesSession
Dim docContext As NotesDocument
Dim strRequestContent As String
Dim lstrFieldPairs List As String
Dim varFieldPairs As Variant
Set docContext = sessCurrent.DocumentContext
Let strRequestContent = docContext.GetItemValue("Request_Content")(0)
Let varFieldPairs = Split(strRequestContent,"&")
Forall strFieldPair In varFieldPairs
Let lstrFieldPairs(Strleft(strFieldPair,"=")) = Strrightback(strFieldPair,"=")
End Forall

Once the list is populated, you can Forall through it and do whatever you want with the data, such as assigning field values on a document, for example:
Forall strFieldValue In lstrFieldPairs
Call docTarget.ReplaceItemValue(Listtag(strFieldValue), strFieldValue)
End Forall

Enjoy...
Technorati tag:

Comments

Gravatar Image1 - Nice, I am build dynamic forms this way that can be defined through documents and it works perfectly even in Java.

Gravatar Image2 - I couldn't agree with you more about Lists. I use them all the time and am starting to develop my own classes that use lists of other custom classes I develop. The ability to directly reference a list member without using loop is invaluable.

Sean---

Contact Me

Hire Me

Elsewhere

What the Quote?

"Two wrongs don't make a right, but three rights make a left."

Michael Nurre

"Then again, you're the only person I know who can sing like bagpipes."

Tim Tripcony

"Who's Jeff Crap-in-the-head?"

Melanie Deal

"Nerve endings? Nah, these are nerve beginnings."

Tim Tripcony

"You'll be just below the Bible Belt. So, anatomically speaking..."

Greg Rotz

Apparel

Lotus Rocks

I write the code that makes the young girls cry