Adobe
GoLive 6 Dynamic Content Samples
Overview
Database Design
Topics
Messages
Create Topic
Manage Topics
Manage Messages
Delete Topic
Delete Message

text

A. Topic name. B. Dynamic table to display messages. C. Username. D. Date of posting. E. Message text. F. Hidden code to clear the form for posting a response. G. Username and text for posting a response. H. Hidden field to specify response topic. I. Form submission button.

Content Sources

There is a single content source, the Messages table from the User Forum database. The content source uses record filtering to select the messages that match the 'Topic' URL parameter. When the user clicks a topic on the Topics page, the URL has the form 'messages.php?Topic=cool stuff'. The content source is sorted by date in descending order, so the most recent message appears first.

Tabs

The Administration View link includes the current topic so that the user sees the same topic when he clicks over to the Administration View. Here is what it looks like in PHP:

messages_admin.php?Topic=<?php echo $Messages->Value("Topic") ?>

The easiest way to add dynamic parameters like this is to use the 'Edit..." flyout in GoLive's link inspector.

A

The topic names is bound to Messages.Topic. This binding really just displays the topic for the first message, but since all the messages on the page have the same topic the effect is correct.

B

The dynamic table is bound to the Messages content source to display all the messages.

C

The first row of the dynamic table is the template row. The username is a simple text binding that displays the username of the person posting a message.

D

The date is formatted with the Format Date and Time filter.

E

The message text uses the Convert Line Endings filter. This filter is similar to putting the text inside of a <PRE> element, except that the text show up in the normal HTML paragraph font. In this case, with all of the filter options checked, the message is treated as ordinary text. If the Encode as HTML option were not checked, then the message could contain HTML markup.

There is a security issue with allowing HTML markup, since a user can include java, javascript, or other code in his messages. Browsers are good at preventing malicious HTML from damaging a system, but since there is no compelling reason to allow HTML markup, it is safest to just use the Encode as HTML option.

F

There is hidden code here to make sure that the form fields in the new posting section are blank. Without this code, the form would display the username and text of the first message. Here is what the code looks like in PHP:

<?php MoveToEnd($Messages) ?>

This code works by moving to the end of the record set. GoLive uses this idiom consistently to display new, empty records.

It is a good idea to include hidden code like this in any form that should be blank. Notice that the hidden code is the first element in the form, so that it will move with the form if the page design changes. To reuse this code simply replace 'Messages' with the name of the content source on your page.

G

The username and response text are simple form control bindings.

H

There is a hidden form element here to set the topic for the new message. The new message must have the same topic as the other messages on the page.

It would be nice to simply bind the hidden element to Messages.Topic. Unfortunately, because the content source now points at an empty record, this approach leaves the topic blank. One solution is to move the hidden element before the custom code that advances the content source to an empty record; then the binding approach works correctly.

The alternative is to use custom code that works correctly with the GoLive Form Actions. Here is what the hidden element looks like in the form control inspector:

text

The expression for the name is copied and pasted from one of the other bound form controls. The part within the angle brackets is the PHP syntax for putting in the record number, so the hidden element will have a name like 'Topic(123)'. It is important to use the same code as the other form controls so that the record numbers match.

The value for the hidden field is the PHP syntax for putting in the 'Topic' parameter from the URL.

Note that there is no hidden field for the message date. The reason is that MessageDate is set up in the database so that it defaults to the current date, today. If it did not have a default value, then the form would need a second hidden element for the date. Whenever you add a record to a database table, you need to provide values for all of the fields that do not have default values.

I

The Form Action for the submit button is Add Record. GoLive automatically targets the correct page in the config/actions folder whenever you select a Form Action.