PHP
  Home arrow PHP arrow Page 5 - Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 76
    2003-03-11


    Table of Contents:
  • Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
  • Adopting A Moderate Approach
  • If Looks Could Kill...
  • Bringing In The Database
  • A Well-Formed Plan
  • When Things Go Wrong
  • Locking It Down
  • Over And Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building A Quick-And-Dirty Guestbook With patGuestbook (part 2) - A Well-Formed Plan
    ( Page 5 of 8 )

    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
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek