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  
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? 
PHP

Completing a Blogger with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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
     

       

    PHP ARTICLES

    - 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...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT