The next step in this series shows how to publish visitor comments on your website, using hosted web service modules from Xara Online. I've already shown how to set up a form to collect comments, how to add a mailer to email an automated response, and how to create a database to save them. This next step introduces two of the most versatile members of the Xara family of connectable modules. It shows how to add a query module to find comments in the database, and a reporter module that you simply cut-and-paste into any page on your website to publish them automatically.
Before getting started, it's worth taking a moment or two to think about the following points:
What information do you want to show on your web page? When visitors submit their comments, the form also asks them for their email address, first name, last name and website URL. This information is recorded in the database, along with the date and time when they submitted their comment. Here's a reminder of the complete list of fields (with their system fieldnames in brackets):
Your email address (email)
First name (fname)
Last name (lname)
Your website URL (siteurl)
Your comment (comment)
Date and time submitted (entry_date)
Apart from the email address (which visitors may wish to keep private), it will be useful to publish all of this information for each comment, using the entry date to order them so that the most recent comment appears first. It's the role of the query to select this information and sort it into the correct order.
How do you want to present the information? My suggested layout is pictured right (click thumbnail for larger version). This is based on the layout I originally used for Loosely Coupled's comments page. There are two separate elements to consider:
The format and layout of the repeating information that will make up the body of the report. In my example, the repeating section displays the comment first, with the submission date, visitor's name and their website URL underneath in a two-column format, followed by a dividing line.
The overall colors and font style of the report, including the non-repeating header and footer. To match the style of the rest of the site, I chose 16pt type for the heading, colored cyan, with a gray dividing line beneath it. At the bottom of the report, I included a footer with page numbering.
For a different site, you might choose an alternative layout, with different colors and font styling. It's up to you you can control all of this formatting from within the reporter module, as explained below.
First you must create the query module, which reads information from your database ready for use by the reporter module. This takes just a minute or two:
On the left-hand menu of your module store, Select Data Manager Database Query Create New. In the center of the next screen, follow the instruction to 'Click here to select a Database module.'
You'll see a screen showing all the suitable modules in your module store. Click on the icon for your database.
Xara automatically creates a query with the same fields as the database, and takes you to the 'simple search' screen in the query editor. Click on the 'advanced' tab.
The advanced screen gives you various options to control the output from the query, and to connect it to other modules, as pictured right (click thumbnail for larger version). Make three small changes to prepare it for our current application:
In the 'Search criteria' section, there's a column of check boxes on the right-hand side headed 'Output'. At the bottom of the column, the box for the 'Entry date' field is unchecked. Click on it to make it checked. This will let you publish the dates when comments were submitted.
Underneath, in the 'Input & Output Options' section, you'll see two drop-down menus. Set the 'Sort output by field:' selection to 'Entry date', and set the 'Sort order:' to 'Descending'. This orders the comments by the dates they were submitted, with the most recent at the top.
Now go all the way down to the 'Advanced' section near the bottom of the page (not shown in our screenshot). Put a check in the box next to 'Execute this query whenever database data changes.' This means the query will update any new comments or other database changes automatically, instantly publishing your visitors' comments as soon as they are submitted.
The final step is to give the query a suitable name (eg "comments_publish") in the small white box at the top right of the screen, and then click the 'save and publish' button.
You're now ready to create the all-important reporter module, which you'll be able to embed in any page of your website to publish your visitor comments online (this first reporter module will also act as a time-saving template when adding other reports to your website later on):
On the left-hand menu of your module store, Select Data Manager Reporter Create New. You'll now go through a short series of screens to set up the module:
In the center of the first screen, click on this line of text: 'Click here to select a module that outputs data.'
The next screen shows all the suitable modules in your module store. Click on the icon for the query module you just created.
On the screen that follows, you'll see a selection of predesigned report styles. Find the 'Basic Report' style, headed "Reporter Module" (at the time of writing, it's the middle picture on the left of the page). Click on it to select it.
This takes you to the 'reporter mode selector' screen. The middle option is 'Public, shared report that all visitors see'. Select this by clicking on the 'select mode' button alongside.
You have now reached the reporter editor, which is very similar to the form editor in step one, with the same editing controls at cell, row and column levels. The first task is to make some global changes to quickly rearrange the default layout of the report:
Xara automatically generates a separate column for each field in the query six columns in all. My layout will only use two of them, so begin by deleting the four unwanted middle columns. Click on the arrowheads above each column in turn, and select the 'delete this column' tool, until you have just two columns remaining.
To remove the two-tone color effect, check the edit boxes on the right-hand side of both the top and bottom rows, and then click on the 'edit selected' button underneath the report table. In the popup edit window, click on the maroon-shaded background color box to bring up the color picker window. Click on 'Transparent' and then 'Set color'. Then click OK to return.
My layout needs an extra row in the body of the report. To insert it, click on the arrowhead for the second row (the one with italicized 'email' and 'comments' headings), and click on the tool to 'insert new row below'. This adds a duplicate row.
Now remove the text centering. Click the 'edit all' button to bring up the 'edit cells' popup. Click on the drop-down menu for 'Cell content: Horizontal', and select 'Left align'. Click OK to return.
You're now ready to begin editing the contents of each individual cell, starting with the repeating section that makes up the body of the report. For this step, you'll need to be able to see the field names that will be merged from the query into the report:
Below the main editing area, you'll see three tabs. Click on the middle tab, called 'input connections'. The box underneath will now show a list of available field names.
Now go up to the top of the editing area, and click on the 'show connections' link. This changes the editing view to show merge codes, so that you can see where the fields are placed in the report (as pictured in 4c below).
You can now move on to edit the formatting and contents of each of the individual cells in the repeating section of the report (we'll come back to the header and footer rows later on):
Moving past the heading, the next row is the beginning of the repeating section, and it's where the comment will go, so the two cells in this row need to be merged into one. Click the edit button for the first cell, and select the cell tool to 'merge with cell on right'. Then click on the edit button for the newly merged cell, and make these other changes:
Click on 'font' to bring up the font selector and remove the italic.
Replace the existing text with the merge code "[[comment]]" and click OK
Now click the edit button for each of the next four cells in turn and edit the text as follows:
In the first cell, change the text to "Posted [[entry_date]] by:"
Moving to the right, change the text in the next cell to "Website:"
Moving to the next row, change the text in the left-hand cell to "[[fname]] [[lname]]"
Moving to the right, change the text in this cell to "[[siteurl]]"
With all of the merge codes in place, the repeating section is complete, as pictured right (click thumbnail for larger version). If appearance doesn't matter to you (or if you want to test the results of your handiwork before you continue), you can now go directly to step 6 and start using the report. Alternatively, carry on to the next step to fine-tune the presentation of the report.
The final stage is to amend the header and footer rows, add some dividing rows and change the background color. These important cosmetic changes will tidy up the appearance of the report, and bring it into line with the look of the site:
Click the edit button for the heading cell. Make the following changes:
In the text box, enter your preferred heading, such as "Latest comments".
Click on 'font' to bring up the font selector window, and click on the color box.
This brings up the color picker so you can select your preferred font color. Either select a color from the grid, or enter an RGB value (for cyan, I entered 0,0,255), and then click 'set color'.
Back in the font selector window, enter your preferred font size (I chose 16pt) and font style (I clicked off the bold), then click OK.
Click OK to finish editing the heading cell.
Now click the purple arrowhead to the left of the heading row. Under the row tools, uncheck the box labelled 'copy contents on new row creation', and then click the row tool to insert a new row below. Now click the arrowhead for the new row so you can edit it to act as a divider:
Click on the background color box. Click on the middle gray in the color picker (or an alternative color of your choice), then 'Set Color'.
Click the radio button next to "Height" and type "1" into the px box (this sets the height to 1 pixel).
Click OK to return (the row will appear to be too thick, but don't worry about that for now).
Now click the arrowhead for the next row (the one containing the comment field). Go to row tools, uncheck the 'copy contents' box, and insert a new row below, which will act as a blank spacer row. Click the arrowhead for the new row, and set the height to 1 pixel.
Go down to the bottom row and click on its arrowhead. Uncheck the 'copy contents' box and insert a new row above (not below). Now click the arrowhead for this new row to turn it into a repeating divider:
Set the height to 1 pixel
Set the background color to middle gray (or your own choice of color)
Uncheck the box next to 'Header/Footer row:' (this makes sure it repeats after each comment).
The last finishing touch adds a pagination control to the footer:
Click the edit button for the single cell on the bottom row, then click the 'Change Cell Type' button.
Select 'Pagination Control' and click OK
The number of records per page controls how many comments will show on a single page. You can choose any number. I started with 3, to avoid having too many stale comments on display.
Select 'font' and change the color to black.
Click OK to return.
Now move down below the main editing area and click on the 'table properties' tab. You'll see that the 'Cell Padding' is set to 4. This is what is making the divider lines too thick. Change it to 0, and set 'Cell Spacing' to 4 instead. Finally, change the background color to transparent.
The reporter is now ready to save. Give it a suitable name in the small white box at the top right of the screen, and then click the 'save and publish' button alongside.
The final screen will show you a line of text with the word SCRIPT at each end. This is the HTML snippet that you'll paste into your web page at the point where you want to publish your comments.
The completed function is now ready to go live, just by pasting that HTML snippet into your web page. The only thing it needs to get started is to receive some information from the query. That will happen automatically as soon as anyone posts a comment. Why not post one yourself to announce that your real-time commenting system is now operational?
posted by Phil 1:37 AM (GMT)
| comments |
Building a website using plug-in online services: the Loosely Coupled experience