NetForms User's Guide: A Simple Example

Let's use the recipe system as our first example. We'll just have users enter recipes (name, ingredients, and directions) and then put the list of recipes in a menu. If you haven't already, take a look at the Recipes example.

First, let's take a look at the Recipe Menu Page. Here is the HTML...


<HTML>
<HEAD>
<TITLE>Recipe Menu</TITLE>
</HEAD>
<BODY>
<H1>Recipe Menu</H1>
If you would like, please 
<A HREF="RecipeEntry.html">enter your favorite recipe</A>
 or browse the recipes entered so far...
<UL>
</UL>
<P>
IMPORTANT: If this page seems to be missing recently added documents, click the 
"Reload Page" button on your Web Browser to update the menu.
<P>
<ADDRESS>
This page is being maintained automatically by NetForms.
</ADDRESS>
</BODY>
</HTML>
The "RecipeMenu.html" file

Note that the original HTML document has no recipe links in it. NetForms will add them automatically as recipes are entered. To do this, it looks for an unordered list to put them into, so the <UL> and </UL> are absolutlely required, even though the list starts out empty.

When someone clicks on the "enter your favorite recipe" link, they will be taken to our entry form (click HERE to see what it looks like) which is made up of standard HTML that looks like this...


<HTML>
<TITLE>Recipe Entry Form</TITLE>
<H1>Recipe Entry Form</H1>
<FORM method=POST action="/NetForms.acgi$/Recipes/Recipe.fdml">
Author: 
<INPUT TYPE="text" NAME="Author" SIZE="30" MAXLENGTH="30">
<P>
Recipe Name: 
<INPUT TYPE="text" NAME="RecipeName" SIZE="30" MAXLENGTH="30">
<P>
Ingredients:<BR>
<TEXTAREA name="Ingredients" rows=10 cols=60></TEXTAREA>
<P>
Directions:<BR>
<TEXTAREA name="Directions" rows=10 cols=60></TEXTAREA>
<P>
<INPUT type=submit value="Submit Recipe"> 
<INPUT type=reset value="Start Over"><P>
</FORM>
</HTML>
The "RecipeEntry.html" file

Notice in particular the 4th line, which is the FORM command. The action portion of this command specifies NetForms as the handling helper application and gives a path to the FDML document that will be used to process the article. The rest of the form is completely standard HTML.

The interesting part of our recipe system is the "Recipe.FDML" file, which is where we specify exactly how each incoming form should be processed. Let's look at the file...


<CREATEDOC>"/Recipes/<REPLACE_FN RecipeName>.html"</CREATEDOC>
<MENUDOC>"/Recipes/RecipeMenu.html" <LI> <A HREF="<HTMLFILENAME>"> <REPLACE RecipeName></A></MENUDOC>
<HTML>
<HEAD>
<TITLE><REPLACE RecipeName></TITLE>
</HEAD>
<BODY>
<H1><REPLACE RecipeName></H1>
<Address>
This article submitted by <REPLACE Author> on <DATE>.
</Address>
<HR>
<H3>Ingredients -</H3>
<BULLET Ingredients>
<P>
<H3>Directions -</H3>
<REPLACE Directions>
<HR>
Article complete.  Click 
<A HREF="/Recipes/RecipeMenu.html">HERE</A>
to return to the Recipe Menu Page.
</BODY>
</HTML>
The "Recipe.FDML" file

Line 1 is required. We're not going to get very far without a CreateDoc directive, which tells NetForms to create a new HTML document, based on the format to follow. Notice the file name and path, the path is specified relative to the MacHTTP "root" folder. It is usually helpful to specify a subfolder which is a level deeper than the one your FDML and other documents are in. This way, all user entered articles are in a single folder, which usually makes the system easier to maintain in the long run. This example is extremely simple though, so we'll just keep everything in the Recipes folder.

Another important thing to notice is that the Replace command works within directives. This is very important, so that we can specify various and (hopefully) unique file names for each article entered.

Line 2 tells NetForms to update the menu page (which is also our Recipe Home Page). It specifies the full path of the HTML document to be updated and then includes HTML syntax to define exactly how the line should look. Within the MenuDoc directive is the command HTMLFILENAME, which will be substituted with a path to the newly created HTML file. Notice also that, in addition to the URL, you can specify what the user will see on the line in the menu too. You could, in addition to just the recipe name, show the author, date, or whatever you like right on the menu. (The date the article was entered is very useful.)

Line 3, the <HTML> command, is absolutely required in an FDML document. It is good form in any HTML doc, but isn't required by most browsers. NetForms, though, uses this line to tell where the NetForms directives end and the HTML formatting begins.

Line 5 inserts the Recipe Name into the title of the document.

Line 8 inserts the Recipe Name into a highlight section right at the top of the document.

Line 14 inserts the ingredient list as a series of bullet points. Bullets probably aren't necessary, but they look nice. If you wanted the ingredients to be plain text, you could just use a REPLACE command, like line 17 does to insert the directions.

That's it, you have a pretty decent Recipe Web Server in just 60 lines of HTML! Now you could use AppleSearch (or another search engine) to index the recipes and perform full text searches.

You may want to poke around a bit at this point. Try making some changes to our example:

When you're feeling like you know what's going on, your ready for the Tricky Example.
NetForms (C) 1994 by Maxum Development Corp.

Return to the contents page