In this section of my tour of my websites, I will look at the Guestbook. I wanted to build a page which would enable users to post comments on Aviation Photo Gallery.
I wanted the guestbook to display the users' posts in the form of a table, and as a series of pages with a maximum of five posts per page. If there are more than five posts, there should be a series of links to the other pages of posts.
Up to five posts are displayed on the guestbook page at any one time. If there are more than five, a series of links is displayed below the table of posts. The number of links required is calculated by dividing the total number of posts by five. The links themselves are created as query strings using the PHP urlencode Clicking one of these links effectively re-submits the guestbook page to itself, only function. displaying a different five posts.
The guestbook form consists of a standard HTML form, which is validated client-side by JavaScript regular expressions.
If the user enters invalid data, an alert box appears with an error message.
When the user submits the guestbook form, the data submitted is processed by a PHP script. Firstly, the data is checked for any unsuitable material. Any posts containing unsuitable material are automatically blocked.
A message is displayed, informing the user that they have attempted to post unsuitable material.
The submitted data is then used in an SQL query to search the guestbook table. The results of this query are displayed in an HTML table, with up to five posts displayed at any one time.
A series of links is displayed below the table of posts. The number of links is calculated by dividing the total number of posts by five. The links themselves are created as query strings using the PHP urlencode function. Clicking one of these links effectively re-submits the guestbook page to itself, only displaying a different five posts.
To see a demonstration of the Aviation Photo Gallery guestbook, click here. The search results will open in a new browser tab.
I have also built a guestbook for my Scottish Mountain Landscapes website. Originally, this website was hand-coded with XHTML 1.0 Transitional, so the guestbook worked in a very similar way to Aviation Photo Gallery.
However, I have now re-built Scottish Mountain Landscapes with the Joomla content management system, so I have used the Sourcerer plugin to integrate the guestbook PHP script into Joomla.
This is the same technique I used to integrate my search engine PHP script into Joomla, as I described in Part 3 of this tour.
Recall that Sourcerer works by placing special tags around any code to be included in Joomla content:
{source}
and {/source}
.
To see a demonstration of the Scottish Mountain Landscapes guestbook, click here. The page will open in a new browser tab.