PHP
  Home arrow PHP arrow Page 4 - Completing a Blogger with PHP
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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? 
PHP

Completing a Blogger with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2006-12-05

    Table of Contents:
  • Completing a Blogger with PHP
  • A quick look at the BlogProcessor class
  • Providing the blog processor with database connectivity
  • Implementing client-side data validation on input forms
  • Improving the blogger’s visual appearance

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Completing a Blogger with PHP - Implementing client-side data validation on input forms


    (Page 4 of 5 )

    As I mentioned in the section that you just read, one of the last improvements that I plan to introduce to expand the existing functionality of the blogger consists essentially of implementing a basic (but effective) validation mechanism on each of the input forms included with the application.

    As you probably already noticed from the beginning, the blogger program originally included a JavaScript file called “valfunctions.js.” Not surprisingly, this file is the container for all the JavaScript functions that will perform a basic validation on each value entered in the two input forms integrated with the application. These input forms were covered in detail in the previous article.

    Regarding the JavaScript-based validation functions contained in the “valfunctions.js” file, they look like this:

    // validate form

    function validateForm(formObj){

                valid=true;

                var title=formObj.elements[0];

                if(!title){return};

                if(!title.value){showError(title,'*Enter a title for
    your blog')};

                var author=formObj.elements[1];

                if(!author){return};

                if(!author.value){showError(author,'*Enter your full
    name')};

                var content=formObj.elements[2];

                if(!content){return};

                if(!content.value){showError(content,'*Enter some
    text for your blog')};

                return valid;

    }

    // show error messages

    function showError(obj,message){

                if(!obj.errorNode){

                obj.onchange=hideError;

                var span=document.createElement('span');

                            span.className='error';

                span.appendChild(document.createTextNode(message));

                obj.parentNode.appendChild(span);

                            obj.errorNode=span;

                }

                valid=false;

                return

    }

    // hide error messages

    function hideError(){

                this.parentNode.removeChild(this.errorNode);

                this.errorNode=null;

                this.onchange=null;

    }

    // execute 'ValidateForm()' function when page is loaded

    window.onload=function(){

                // check if browser is W3CDOM compatible

                if(document.getElementById&&document.
    getElementsByTagName&&document.createElement){

                            var insform=document.getElementById
    ('insertform');

                            if(insform){insform.onsubmit=function()
    {return validateForm(this)}};

                            var updform=document.getElementById
    ('updateform');

                            if(updform){updform.onsubmit=function()
    {return validateForm(this)}};

        }

    }

    As you’ll realize, the group of validation functions listed above performs a basic verification on the data entered in the corresponding blog insertion form of the application, as well on the one used for updating existing entries. It’s not my intention to develop a full-featured validation system here, since that will be certainly out of the scope of this series. However, the JavaScript data checking system that I coded previously really works decently when it comes to verifying whether or not a particular input box has been filled.

    Okay, at this stage, the blogger is now capable of validating, at least basically, any data entered into the corresponding input forms. The last step required for completing the application rests simply on adding some CSS styles to the (X)HTML markup that structures the program, improving its look and feel.

    As you might have guessed, all these useful tasks will be performed in the next few lines, thus jump forward into next section. I’ll be there, waiting for you.

    More PHP Articles
    More By Alejandro Gervasio


       · In this final part of the series, the PHP 5-based blogger is completed. This process...
       · Another nice article Alejandro, it hints at an object oriented approach to any kind...
       · Hi Jon,Thank you for the kind comments in my PHP article. I appreciate that, and...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT