Creating In-line Response Documents

Jake Howlett, 20 August 2002

Category: Forms; Keywords: Response Form CreateDocument

More often that not a Domino database will have some type of parent-child document relationship. When the authoring of such documents is implemented in the browser I think we should all be familiar with the way these relationships function and behave. Let's take the Discussion Forum on Notes.net for example. When you go in and read a document you have the option to add your replies in order to help out the troubled person. To do this you find the link to the Response form, wait for the page to open and then fill out the form before finally submitting your response. Not only can this sometimes be slow it is an extra step we can easily do without. That is what I will discuss how to do in this article.

By giving the user the ability to add their responses directly from the parent document that they are reading we can make their life an awful lot easier. Another bonus to this approach is that the user never has to leave the page they are reading and hence they can easily check what it was they were actaully reading as it's still on that page. To see what I mean you can see this approach being used in the blog on the homepage of codestore. If you open one of the posts then you will notice that there is a form at the bottom. Filling out the fields and pressing the post button adds a repsonse to it and then returns you to the blog document again. You can see this layout in the screen-grab below:

Inline Form

Notice that below the actual content of the document we also have a view of the blog's responses and then we have the form that means we can add our own.

How can we possibly do this:

To create a document in a Domino database without actually opening the form itself we make use of the ?CreateDocument URL Command. When we use this as the action for the POST request of our form we can pass in field values and Domino will be non-the-wiser as to how we created the document. In the case of a Response document architecture the URL that we would normally expect as the form's action is something like this:

db.nsf/ResponseForm?CreateDocument&ParentUNID=2935DC...72

All we have to do is add a form to all our documents and make sure that the action attribute of the form points to the right place and that it has all the rquired fields on it in order to create the necessary response document.

Before I describe the ins and outs I will assume that you have some kind of web-enabled Domino Discussion database at hand. If not you can create one from the template or, better yet, download my example which has this trick built in already and which I will be describing.

What I am not going to be talking about is how to set up your documents so that they actually function in a parent/child relationship. This is "beyond the scope", as they say.

The quick and easy form:

First thing to do is open your parent form. In the case of my database it is called "Document". At the end of your standard form (i.e under all your fields) we need to add some Passthru HTML that will close off Domino's own form, letting us create our own. The HTML for this is:
</form>
<form action="Response?CreateDocument&ParentUNID=<Computed Value>" method="post" onsubmit="return validatePost(this);" enctype="multipart/form-data">

Notice in the above code that we have pointed the form to the response form which is called, wait for it, "Response". Note also that we have passed to it the ParentUNID parameter which tells it which document it is to become a child of and inherit its values from. The Computed Value you can see above is simply the Document Unique ID of the parent and is just the following @Formula:

@Text(@DocumentUniqueID)

All we need to do now is add the fields that are going to be passed in, via our new form, to the child document. To do this we can use more Passthru HTML as the fields don't need to exist on the main form (although they DO need to be on the target form for it to work). How many fields you need to add depends on how many there are on the actual response form. In the case of my example there are only three and I add them like the one below:

<input name="Title" type="text" value="<Computed Value>" />
In this field's case the Computed Value is there simply to give this field a default value and I have used the following formula:

"Re: " + Title
This way it defaults to looking like it is a response to the document which you are currently in, which also has a field called "Title".

Now the important part - The "Submit" button. Because we've created our own form we can't rely on Domino to create the button for us and so we need to create our own. Here's the HTML I added to the form to do this:

<input type="button" value="Submit" onclick="this.form.submit()" />
Notice how I used JavaScript to tell the button to submit this form. Even when in read-mode, Domino, for some unknown reason, generates its own form by default. This means there are two forms in the page and so we could equally have the JavaScript for the button access the form object as document.forms[1]. However, I find it's cleaner to use this.form where "this" is the button object and "form" is its parent form object. How you do it is up to you.

You now have all you need for the new form. Note that there is no need for the closing tag of the form that we have opened as this will be closed by the tag that Domino created in order to close its own form.

The only thing left to do is check that the Response form is setup properly and that all the fields you created using Passthru are in place. You can then add a $$Return field in which you can redirect the response to browser after the form is submitted back to the original document if you like.

Having added the form to the Parent document you now need to repeat the procedure for the Response form as well. Once you've done the user can add responses to any document from anywhere in the hierarchy of posts.

All in all, your forms should look something like the one shown in the sreengrab below:

Inline Form

Okay, I know, it looks a bit messy and may seem like a bit of a hack. Something I am too aware of is that having years of experience with Domino leaves you with the impression that this is what you have to do if you really want to get the most out of it. Learn to apply combinations of all the tricks you learn along the way and you're on to a winner.

A little bit of tidying up:

There are of course a few things I've neglected to mention in the course of describing this to you. Hopefully they will all be fairly obvious when you start to look at the example database. Things like hiding our new form when @IsNewDoc or when in edit mode...

Another point worth consideration is the "Generate HTML for all fields" feature. Why anybody would ever want to use it is beyond me but, all the same, people do. If your parent form has it enabled and you use this approach you may observer strange side-effects. This is becasue Domino will add all these "hidden" fields at the bottom and so they will be a part our new form. Hence, not only will the reponse documents inherit all these fields, you will see errors if any of these fields happen to not feature in the design of the receiving form. If you want my opinion - turn it off!