Web DevCenter
oreilly.comSafari Books Online.Conferences.
MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

Sponsored Developer Resources

Web Columns
Adobe GoLive
Essential JavaScript

Web Topics
All Articles
Scripting Languages

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed

Learning Lab

Extending GoLive 6's Dynamic Content
Creating Blank Forms and Default Values

by Derry Thompson

Let's say you've set up a form using Dynamic Content in GoLive 6. All appears to be going smoothly. But when you try to add a record, you see the first record in the chosen data table displayed in your form instead of a blank form. The manual says to use the "show details of empty record" action to get a blank form. But what if you can't link to the page? What if the form is on your home page? What if it's a specific entry page? What if you want to use default values in your field, such as the date?

This article details two solutions for presenting a blank form.

Presenting a Blank Form

Method 1

Set up your form as normal, bind all your form fields to the database fields, and then set up the submit button action to "Add a new Record".

Example showing a form using the standard Dynamic Content Bindings
A form using the standard Dynamic Content Bindings.

Now switch to Source mode, locate the form tag, and then locate your first form field.

Source view with a form field highlighted
Source view with a form field highlighted

You should see something like the above. In this example we're binding to a field called TTL, which is the title of our news item.

<input type="text" name='TTL(<?php echo $news->AbsolutePosition()?>)'
   value='<?php echo fixHTMLquotes($news->Value("TTL")) ?>'
   size="24" border="0">

Dynamic Content has assigned the field name and the field value. To display a blank form that will still add a record to your database, simply remove the field value that Dynamic Content has assigned to it. You will end up with something like this:

<input type="text" name='TTL(<?php echo $test->AbsolutePosition()?>)'
   value='' size="24" border="0">

Repeat this for all the fields in your form. Although GoLive 6 no longer recognizes the fields as bound fields in the Dynamic Content bindings tab, it works. You'll be able to display a blank form that will still add a record to your database table.

Example showing the form after source has been edited.
The form after source has been edited.

Method 2

Set up your form as normal, and then name all the fields to match that of your database fields. You need to use the format:

TTL(<?php echo $test->AbsolutePosition()?>)

where TTL equals the name of the database field you would like to bind to. You can't use the database field name as GoLive 6 will not recognize it as a valid Dynamic Content link.

Using either of these methods will enable you to present a blank form which will still add a record to the database without using a link to get to the page.

Using Default values

Using the methods described above also enables you to set up pre-defined values for a field.

For example, you may want to record the date that the record was entered. In this case you can use PHP's date function to assign the current server date.

In our example we have a date field:

DTE(<?php echo $news->AbsolutePosition()?>)

To assign a default value of today's date, we would select the field and then enter this in the value section of the inspector:

<?echo date ("F Js Y")?>

Using the Inspector to set default Values
Using the Inspector to set default Values

The source code would then look like this:

<input type="text" name='DTE(<?php echo $news->AbsolutePosition()?>)'
   value='<?echo date ("F jS Y")?>' size="24" border="0">

Related Articles:

Converting Your Site To GoLive -- Adobe GoLive 6 is great if you're starting a Web site from scratch, but how do you maintain an existing site with GoLive's sophisticated tools? Deborah Shadovitz shows you how, step by step, in this first of a series of articles.

GoLive 6: Adobe's Open Source Embrace -- It's not your newbie's GoLive anymore. Version 6 supports ASP, JSP, and the Internet-favorite PHP for database integration of content, plus a full set of preconfigured servers for both Mac OS X and Windows XP/2000. Glenn Fleishman shows you how to fire up this hot rod.

The date can be formatted in a variety of ways. The technique we've used here would show the date in the format "April 22nd 2002." If we wanted to show the date in the format "Monday April 22nd 2002," we would use:

<?echo date ("l F jS Y")?> . 

You can find a full explanation of the date function here.

You can use anything you like as a default. We may want to read the author's name from a cookie value or set a dummy article title for an example. As long as the field name is set up to match your database field name, these default values will get passed across and saved.


Both of the above methods allow you to have more control over your forms while utilizing the power of GoLive 6 Dynamic Content.

Derry Thompson is currently co-owner of GloDerWorks with his partner Gloria Hansen. An active participant in the GoLive community and an avid Mac user, he can be found in various airports using his Titanium G4 Powerbook.

Return to the Web Development DevCenter.