Guestbook Administration - F.A.Q
1. What is a template and why does the guestbook use templates?
2. Do I need to know PHP in order to change the template design so that it looks like my website?
3. I do not want to change the original design but just its color scheme. How to achieve this?
4. What template engine does the guestbook use?
5. Tell me more about templates.
6. How to change the template, so that the guestbook looks like my other web pages (part #1)?
7. How to change the template, so that the guestbook looks like my other web pages (part #2)?
8. How to change the template, so that the guestbook looks like my other web pages (part #3)?
9. There are also other template files. What are they for?
10. Finally, edit the language file.
11. I edited everything as instructed. Now what?
Q: What is a template and why does the guestbook use templates?
A: Templates provide web developers with a way to easily separate the web site design from the complicated server-side coding. To sum it up, the template engine running on the server parses a template, substitutes all variables (denoted {VARIABLE}) with the corresponding values, and then provides the result to the browser. Templates allow you to fit the guestbook within the design of your website without knowledge of PHP or any other programming languages.
Q: Do I need to know PHP in order to change the template design so that it looks like my website?
A: No. Templates are different from web pages only in the fact that some of the text is substituted by variables (such as {VARIABLE}). You will need to have experience with HTML and web design though.
Q: I do not want to change the original design but just its color scheme. How to achieve this?
A: The original guestbook design is fully CSS based. Simply edit the client front-end CSS file "html/user.css".
Q: What template engine does the guestbook use?
A: The guestbook uses the patTemplate engine: http://www.php-tools.de/.
Q: Tell me more about templates.

A: We will use analogy to explain templates: a business letter can be divided into pre-defined parts: sender's address, recipient's address, subject, address, body, signature. If you know all the information for these parts, you can easily write the letter by simply ordering the information accordingly.

Templates follow the same logic:
1. You divide your website into parts, such as header, footer, paging links, error message section, etc.
2. According to the input you feed to the PHP script, it parses the appropriate template, fills it with information and displays the accordingly generated web page.

Q: How to change the template, so that the guestbook looks like my other web pages (part #1)?

A: First you have to design one separate static web page for the guestbook. In this tutorial we will show you how we will integrate the template into such a sample website. We designed the following simple static web page, that shows all possible actions that may occur - an error message, a success message, and a red (wrongly filled in) field:

The above web page can be divided into the following templates (parts):
1. Header - this is the menu on the left and the TITLE - these elements are always present.
2. Error message - this is shown when the visitor supplied bad information to the form.
3. Success message - this is shown when a new comment was added successfully.
4. Paging - these are links which help you navigate through your comments.
5. Form - the visitor enters information here.
6. Comment - an already posted comment.
7. Footer - this part usually contains the HTML tags which close the page but could also contain a bottom menu, etc.

Q: How to change the template, so that the guestbook looks like my other web pages (part #2)?

A: Next, you have to put your HTML code into the template files, so that your design is actually used. To achieve this, you have to divide the HTML code in parts which correspond to the template parts we described above. Here is how we divided our sample page in the 7 parts:

The parts are as follows:
1. Header - the top white block.
2. Error message - the red block.
3. Success message - the dark green block.
4. Paging - the 2 yellow blocks - up and down.
5. Form - the blue block.
6. Comment - the light green block.
7. Footer - the bottom white block.

Q: How to change the template, so that the guestbook looks like my other web pages (part #3)?

A: All you have to do now is put your HTML code in the template files and also follow some rules which apply to templates. We will do this for each of the template files (parts) for you as an example:

1. Header - tpl/client_header.tpl

We did the following:
- Copied the whole HTML text of the Header part of our sample page to the file "tpl/client_header.tpl".
- Replaced the Title texts with the variable {TITLE}.
- Replaced the Encoding specification text with the variable {PAGE_ENCODING}.
- Added 2 JavaScript lines in the <head> tag. Their functions will be used later to validate the supplied user input and for the BBCode feature.

The template engine will replace the {TITLE} variable with the corresponding title text, before the HTML is provided to the visitor's browser. The same applies for the {PAGE_ENCODING} variable. It will be replaced with the encoding scheme you configured in the Admin panel of your guestbook.

Note:
1. The changes we made are marked RED in the HTML code. This rule will apply to our next examples as well.
2. New code that we added is marked GREEN. It is present in the original template and you simply have to leave it there.
3. Special template parts, which must be always present, are marked BLUE. They are present in the original template provided by us as well, and you would have to leave them there.

2. Error message - tpl/client_error.tpl

We did the following:
- Copied the whole HTML line of the Error message part of our sample page to the file "tpl/client_error.tpl".
- Replaced the error text with the variable {ERROR_MSG}.
- Left the line marked BLUE unchanged.

3. Success message - tpl/client_thanks_short.tpl

We did the following:
- Copied the whole HTML line of the Success message part of our sample page to the file "tpl/client_thanks_short.tpl".

4. Paging - tpl/client_paging.tpl

We did the following:
- Removed any CSS style tags and other unneeded tags from the original "tpl/client_paging.tpl".
- Replaced the "Prev", "|" and "Next" texts in the template.
- Put our "<hr>" tags (as they are part of our HTML code).
- Replaced the numbers 1 and 2 with the variable {PAGE_NUMBER}.
- The tags {PAGE_FIRST_URL}, {PAGE_PREV_URL}, {PAGE_URL}, {PAGE_NEXT_URL}, {PAGE_LAST_URL} are respectively the URL addresses of the first page, of the previous page, of the page with number {PAGE_NUMBER}, of the next page, and of the last page.
- For simplicity, in this example the URL links for the "First" and "Last" pages are removed.

The paging for most websites look similar and therefore the paging template would rarely need any changes.

5. Form - tpl/client_form.tpl
Modifying the form is the hardest part, because the design of the form changes dynamically - upon error, the field subjects become red, the required stars disappear, and the message explaining that some of the fields are required also disappears. Furthermore, the form <input> fields have to display some data supplied by the script, so that the visitor does not have to re-enter the whole input information upon error (i.e. the script re-submits the user input to the form). Also the <input> maximum length dynamically depends on the configuration of the guestbook and the protection image. Additionally, the BBCode buttons are shown/hidden depending on the configuration of the guestbook.

Form begin:

We did the following:
- Inserted a <form> HTML tag, with action property {U_POST_FORM}.
- Added a JavaScript action in the <form> tag. The JavaScript function is used to validate the input fields filled in by the user.

Input fields:
This is how to modify the "Subject + input field" part of the form:

We did the following:
- First, we designed how the Subject field text layout will be coded in HTML when there is no error.
- Copied our <tr> and </tr> lines.
- Copied the whole HTML line which shows the Subject field text in red (upon error).
- Copied the whole HTML line which shows the Subject field text normally (without an error) and replaced the star with the variable {SUBJECT_STAR}.
- We left the original <input> HTML tag as it already has all template variables and names configured ({F_SUBJECT}, {F_SUBJECT_LENGTH}, name="subject").
- We deleted the class="mainfield" definition from the original <input> HTML tag as our web page does not use CSS.

The fields Name, E-mail, Location, and Homepage are to be modified in exactly the same way.

What is left is the Comment field + BBCode buttons, Image protection field, and the submit buttons. We will briefly show how to embed these blocks too.

Comment:

The green JavaScript code's function is to insert the appropriate BBCode tag when a button is clicked.
We added the {COMMENT_STAR} and the {F_COMMENT} tags at the appropriate place.

Image Protection:

We made the template code simple, because the <input> field will not get red upon error (as it does in the original template supplied with the guestbook). Pay attention that the <input> tag name must be "code" and do not forget to replace the location of the image with {U_SECURITY_IMG}.

Submit Buttons:

Pay attention that the <input> tags names must be "submit" and "preview", and do not forget to leave the original lines (marked BLUE).

6. Comment - tpl/client_comment.tpl

We did the following:
- Copied the <a name> line from the original template
- Replaced all text with the respective template variables {P_SUBJECT}, {P_NAME}, {P_EMAIL}, {P_LOCATION} and {P_COMMENT}
- Copied the <a href> HTML link from the original template ({P_HOME_PAGE})

Note that the template engine lets you add 3 more variables in this template:
- {P_LINE} - This shows the comment number, or the word "New" if this is a Preview. The word "New" can be configured in the "tpl/language.php" file.
- {P_DATE_TIME_READABLE} - This shows the date/time when the comment was made. The format of the date/time string can be configured in the Admin panel.
- {P_IP_ADDRESS} - This shows the IP address of the person who posted the comment.

7. Footer - tpl/client_footer.tpl

We did not make any changes here:


Q: There are also other template files. What are they for?

A:

1. tpl/client_thanks_header.tpl
2. tpl/client_thanks_footer.tpl
If you choose to show a separate "Thank you" page upon a new post, the page will be constructed from these 2 templates and "tpl/client_comment.tpl". These 2 templates are just the HTML code, which will be added before and after the comment. We will use the following in our example for both these template files:

Make sure that you set the URL link to "?mode=1". In this case the links will be shown before and after the new comment posted by the visitor.

3. tpl/client_banned.tpl
This page will be shown when the visitor's IP address is banned. Note that you must have a complete HTML page in this template file as only this file will be shown to the visitor, nothing more.

4. tpl/short.tpl
This template is used in mode=4. You can use all template tags from "tpl/client_comment.tpl" in this template.
The special mode=4 is used to generate a short list with the last comments in your guestbook. This is useful if you want to embed the last several comments from your guestbook in your main page for example. When someone posts a comment, this comment will appear automatically on your main page. Note that you have to embed this mode=4 page via SSI (Server-Side Includes) or using some other HTTP include like the PHP fopen() function for example.

The GET parameters which you can use follow:
page - by default this is 0, the page with the lastly posted entries.
brief - cut every line up to the character number specified by this parameter. Default is 0, which means that lines will not be wrapped at all.
n - this parameter specifies how many entries should be displayed.

Let us give you 2 examples.
If you want to show the last 3 comments, you have to open the following URL address:
http://example.com/guestbook/index.php?mode=4&n=3
If you want to show the last 2 comments and that lines are not longer than 15 characters, use the following URL address:
http://example.com/guestbook/index.php?mode=4&n=2&brief=15

Make sure that you replace "http://example.com/guestbook" with the correct path to your guestbook installation.

5. tpl/client_new_post_email.tpl
The guestbook uses this template to generate the automatic email which the webmaster receives when a new post is added to their guestbook (if this option is enabled in the Admin panel). In this example we did not change the default template. You can use the following template variables: {IP_ADDRESS}, {DATE_TIME_READABLE}, {SUBJECT}, {NAME}, {EMAIL}, {LOCATION}, {HOME_PAGE}, {COMMENT}, {ADMIN_PANEL_URL}. The variable "{ADMIN_PANEL_URL}" contains the URL address of the Admin panel of the guestbook.

6. tpl/client.tpl
This is the main client template, which defines the order and the layout of the front-end templates. Modifying this template requires excellent knowledge of HTML and templates. The default template should be okay for most websites.
Q: Finally, edit the language file.
A: The language file is located in "tpl/language.php". This is a PHP file, so make sure that you keep the syntax of the file correct. You can edit the Page Titles, BBCode Hints, Field Names (they are used in the JavaScript validator script), Error Messages, The field Star in the Form (*) and some other miscellaneous language-dependent messages.
Q: I edited everything as instructed. Now what?

A: If you followed the instructions carefully, you should have the guestbook running with your own website's design:

Template Integration | Template Variables | Config / Admin Section