Home arrow PHP arrow Page 5 - Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)

A Well-Formed Plan - PHP

In this concluding article of our two-part series on rapid guestbook implementation with patGuestbook, find out how to tweak patGuestbook a litle more by controlling the viewable entries, customizing the user interface, and protecting access to the administration module.

TABLE OF CONTENTS:
  1. Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
  2. Adopting A Moderate Approach
  3. If Looks Could Kill...
  4. Bringing In The Database
  5. A Well-Formed Plan
  6. When Things Go Wrong
  7. Locking It Down
  8. Over And Out
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 76
March 11, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
So that takes care of the main guestbook page - now how about customizing the input form for new entries?

Here's what it should look like,



and here's the code that makes it happen:

<form action="{DISPATCHER}" method="post" name="adder"> <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"> <tr> <td align="center"> <input type="hidden" name="action" value="addEntry"> <input type="hidden" name="save" value="yes"> <table width="550" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"> <td> </td> <td width="100%"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="textinvert" align="center">Welcome to {GB_NAME}!<br><br> </td> </tr> </table> </td> <td width="100%" align="right"> </td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td > </td> <td width="100%" bgcolor="#FFFFFF" class="text"> <!-- message for moderated guestbook --> <pattemplate:tmpl name="moderated" visibility="hidden"> Note that this guestbook is moderated, and your entry will only appear in the list of entries once it has been approved by a moderator.<br><br> </pattemplate:tmpl> <!-- errors --> <pattemplate:tmpl name="errors" visibility="hidden"> <table width="400" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="text"> Ooops, I've found some errors in your entries... please check them again:<br> <img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"><br> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <pattemplate:tmpl name="errorEntry" type="condition" conditionvar="err_code"> <pattemplate:sub condition="invalid_email"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: The email you entered is of a type unknown to the net as it exists today. Please enter something a little more comprehensible.</td> </tr> </pattemplate:sub> <pattemplate:sub condition="invalid_url"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: The url you entered is of a type unknown to the net as it exists today. Please enter something a little more comprehensible.</td> </tr> </pattemplate:sub> <pattemplate:sub condition="field_required"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: This field is required, but you left it utterly empty. Please feed it something to make it happy :)</td> </tr> </pattemplate:sub> <pattemplate:sub condition="rating_required"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: You've forgotten to give a rating for this item...</td> </tr> </pattemplate:sub> </pattemplate:tmpl> </table> </td> </tr> </table> <br> </pattemplate:tmpl> <table border="0" cellpadding="0" cellspacing="2" width="100%"> <pattemplate:tmpl name="displayName" visibility="hidden" varscope="page"> <tr> <td class="text" nowrap><b>{LABEL_NAME}</b></td> <td class="text"> : </td> <td width="100%"><input type="text" name="data[name]" value="{ENTRY_NAME}" size="30" class="text" style="width:95%"></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayEmail" visibility="hidden" varscope="page"> <tr> <td class="text" nowrap><b>{LABEL_EMAIL}</b></td> <td class="text"> : </td> <td width="100%"><input type="text" name="data[email]" value="{ENTRY_EMAIL}" size="30" class="text" style="width:95%"></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayHomepage" visibility="hidden" varscope="page"> <tr> <td class="text" nowrap><b>{LABEL_HOMEPAGE}</b></td> <td class="text"> : </td> <td width="100%"><input type="text" name="data[homepage]" value="{ENTRY_HOMEPAGE}" size="30" class="text" style="width:95%"></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayEntry" visibility="hidden" varscope="page"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="6" alt="" border="0"></td> </tr> <tr> <td class="text" colspan="3"><b>{LABEL_ENTRY}</b></td> </tr> <tr> <td colspan="3"><textarea name="data[entry]" rows="5" cols="50" class="text" style="width:95%">{ENTRY_ENTRY}</textarea></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="ratings" visibility="hidden"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="6" alt="" border="0"></td> </tr> <tr> <td class="text" colspan="3"><b>{RATINGS}</b></td> </tr> <pattemplate:tmpl name="ratingEntry"> <tr> <td class="text" nowrap><b>{RATING_LABEL}</b></td> <td class="text"> : </td> <td width="100%"> <select name="data[ratings][]" class="text" size="1" style="width:95%"> <option value="">Please select a rating...</option> <pattemplate:tmpl name="ratingEntryValue" type="condition" conditionvar="rating_selected"> <pattemplate:sub condition="yes"> <option value="{RATING_VALUE}" selected>{RATING_VALUE}</option> </pattemplate:sub> <pattemplate:sub condition="default"> <option value="{RATING_VALUE}">{RATING_VALUE}</option> </pattemplate:sub> </pattemplate:tmpl> </select> </td> </tr> </pattemplate:tmpl> </pattemplate:tmpl> </table> </td> <td > </td> </tr> </table> </td> </tr> </table> <br> <table bgcolor="#FFFFFF" width="550" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center"><input type="submit" value="Submit your entry to our guestbook..." ></td> </tr> </table> </td> </tr> </table> </form>
Ugly isn't it?

1. First, the page header, displaying the name of the guestbook.

<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="textinvert" align="center"> Welcome to {GB_NAME}!<br><br> </td> </tr> </table>
2. The template that displays a message to the user when moderation follows the header.

<!-- message for moderated guestbook --> <pattemplate:tmpl name="moderated" visibility="hidden"> Note that this guestbook is moderated, and your entry will only appear in the list of entries once it has been approved by a moderator.<br><br> </pattemplate:tmpl>
3. This is followed by a list of error messages, which are displayed when required fields are left empty.

<!-- errors --> <pattemplate:tmpl name="errors" visibility="hidden"> <table width="400" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="text"> Ooops, I've found some errors in your entries... please check them again:<br> <img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"><br> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <pattemplate:tmpl name="errorEntry" type="condition" conditionvar="err_code"> <pattemplate:sub condition="invalid_email"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: The email you entered is of a type unknown to the net as it exists today. Please enter something a little more comprehensible.</td> </tr> </pattemplate:sub> <pattemplate:sub condition="invalid_url"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: The url you entered is of a type unknown to the net as it exists today. Please enter something a little more comprehensible.</td> </tr> </pattemplate:sub> <pattemplate:sub condition="field_required"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: This field is required, but you left it utterly empty. Please feed it something to make it happy :)</td> </tr> </pattemplate:sub> <pattemplate:sub condition="rating_required"> <tr valign="top"> <td class="text"> </td> <td class="text">{ERR_FIELD}: You've forgotten to give a rating for this item...</td> </tr> </pattemplate:sub> </pattemplate:tmpl> </table> </td> </tr> </table> <br> </pattemplate:tmpl>
Feel free to edit the error messages above to reflect the personality and style of your site.

4. Finally, the meat of the template - the form that is displayed to the user. As usual, there are pre-defined patGuestbook templates that I can work with for this section. Remember to be careful when tweaking these templates (unless, of course, you're comfortable with patTemplate, in which case, tweak away!).

<table border="0" cellpadding="0" cellspacing="2" width="100%"> <pattemplate:tmpl name="displayName" visibility="hidden" varscope="page"> <tr> <td class="text" nowrap><b>{LABEL_NAME}</b></td> <td class="text"> : </td> <td width="100%"><input type="text" name="data[name]" value="{ENTRY_NAME}" size="30" class="text" style="width:95%"></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayEmail" visibility="hidden" varscope="page"> <tr> <td class="text" nowrap><b>{LABEL_EMAIL}</b></td> <td class="text"> : </td> <td width="100%"><input type="text" name="data[email]" value="{ENTRY_EMAIL}" size="30" class="text" style="width:95%"></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayHomepage" visibility="hidden" varscope="page"> <tr> <td class="text" nowrap><b>{LABEL_HOMEPAGE}</b></td> <td class="text"> : </td> <td width="100%"><input type="text" name="data[homepage]" value="{ENTRY_HOMEPAGE}" size="30" class="text" style="width:95%"></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayEntry" visibility="hidden" varscope="page"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="6" alt="" border="0"></td> </tr> <tr> <td class="text" colspan="3"><b>{LABEL_ENTRY}</b></td> </tr> <tr> <td colspan="3"><textarea name="data[entry]" rows="5" cols="50" class="text" style="width:95%">{ENTRY_ENTRY}</textarea></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="ratings" visibility="hidden"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="6" alt="" border="0"></td> </tr> <tr> <td class="text" colspan="3"><b>{RATINGS}</b></td> </tr> <pattemplate:tmpl name="ratingEntry"> <tr> <td class="text" nowrap><b>{RATING_LABEL}</b></td> <td class="text"> : </td> <td width="100%"> <select name="data[ratings][]" class="text" size="1" style="width:95%"> <option value="">Please select a rating...</option> <pattemplate:tmpl name="ratingEntryValue" type="condition" conditionvar="rating_selected"> <pattemplate:sub condition="yes"> <option value="{RATING_VALUE}" selected>{RATING_VALUE}</option> </pattemplate:sub> <pattemplate:sub condition="default"> <option value="{RATING_VALUE}">{RATING_VALUE}</option> </pattemplate:sub> </pattemplate:tmpl> </select> </td> </tr> </pattemplate:tmpl> </pattemplate:tmpl> </table>
For each field in the guestbook, I have two tags - one displaying the label and the other displaying the form field to the user. For example, for the user's name, I've used the {LABEL_NAME} variable for the label and the {ENTRY_NAME} variable for the text box that is displayed to the user.

 
 
>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: