Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

Expandable Form Validation Class : Part 1

pages (4): 1 [2] 3 4


The Class Attributes



<?php

class datVForm
{
    
/**
     * Form field names including the keywords.
     *
     * @var array
     */
    
var $_f_cFName;
    
/**
     * Form data.
     *
     * @var array
     */
    
var $_f_data;
    
/**
     * Form field names without the keywords.
     *
     * @var array
     */
    
var $_f_tFName;
    
/**
     * Form method.
     *
     * @var string
     */
    
var $_f_type;

    
/**
     * Form validation error messages.
     *
     * @var array
     */
    
var $_l_fError;
    
/**
     * Class system error messages.
     *
     * @var array
     */
    
var $_l_sError;

    
//////////////////////////////////////////////////////////////////////

?>

The Class Attributes are the variables that are shared between all Class Methods. From the comments you can pretty much determine what each Attribute is used for, but there are several that need some clarification.

$_f_cFName is an array housing the form field names in the order in which they appear in the form. The Class automatically appends each keyword associated with each field to the start of it's name. This array houses each form field name with the keywords included.

$_f_tFName is also an array housing the form field names in the order in which they appear in the form. The only difference is that it does so without the keywords included. Why? So when a form error is generated, only the field name is included, not the keywords as well.

$_f_type is whether the form was submitted via a POST or GET method.



The Constructor

<?php

    
/**
     * Constructor.
     *
     * The Constructor has several jobs. First based on the form
     * method type, POST or GET, it will get all form data from
     * the PHP Super Global. Also it defines the attributes that
     * will be used by the Class.
     */
    
function datVForm$f_type )
    {
        
// Initialize Class Variables.

        
$this->_f_cFName    = array( );
        
$this->_f_data      = array( );
        
$this->_f_tFName    = array( );
        
$this->_f_type      $f_type;
        
$this->_l_fError    = array( );
        
$this->_l_sError    = array( );

        
// Determine Form Method.

        
if( $this->_f_type == 'p' ) {
            
$this->_f_data datLib::string_trim_array$_POST );
        }
        else if( 
$this->_f_type == 'g' ) {
            
$this->_f_data datLib::string_trim_array$_GET );
        }
        else {
            
$this->_l_sError[] =    'datVForm() Method : Invalid Form ' .
                                    
'Method :: Ignore Validation : <em>' .
                                    
'All Fields</em>';
        }
    }

    
//////////////////////////////////////////////////////////////////////

?>

The Constructor Method is used when an object is first created. First, it accepts one argument, which is the form submission Method. It uses it to save the form data from either the POST or GET PHP Super Global. There are several things to notice, particularly in this code section:

<?php

        
// Determine Form Method.

        
if( $this->_f_type == 'p' ) {
            
$this->_f_data datLib::string_trim_array$_POST );
        }
        else if( 
$this->_f_type == 'g' ) {
            
$this->_f_data datLib::string_trim_array$_GET );
        }
        else {
            
$this->_l_sError[] =    'datVForm() Method : Invalid Form ' .
                                    
'Method :: Ignore Validation : <em>' .
                                    
'All Fields</em>';
        }

    
//////////////////////////////////////////////////////////////////////

?>

We used datLib Method string_trim_array to trim all the form data before saving it in our Class. We did that so that no extra white space characters are included to avoid any errors in validation.

Consider a validation for a field that can not have any new line characters in it for example. If the User by mistake included a new line character by pressing the enter key before submitting the form, an error message will always be triggered. To save us and the User the headache, we just trim the data.

We also make sure that the form submission method was either POST or GET, or a system error will be triggered to inform us that an invalid method was detected.

- Tutorial written by Limitless

Pages (4): <Prev 1 [2] 3 4 Next>
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments

User:  LimitLess (#32221)
Date: Sun Sep 24, 2006. 20:42:12

Post #2 of 2

Hello,

The download link for "datVForm" was taken offline because we are rewritting version 2 of the libary which is designed from the ground up to take advantage of PHP 5's object model as well as make expansion a little more easier for developers.

This of course will also mean that validation will execute so much faster. I'll let Man1c know when we release version 2 of "datVForm" so that all that benefited from this tutorial can download and enjoy it.

Reply to this post


User:  cool5353 (#31788)
Date: Sun Sep 10, 2006. 10:35:46

Post #1 of 2

I cannot locate a download link for the "datVform" which is mentioned in the article. The Limitless Studios site does not provide the link. Is this source code available elswhere ?

Reply to this post


--- View Entire Thread ---
Amazing Font Pack!

Featured Tutorialsmore

Inset Lines
Inset Lines
- Adobe Photoshop -
Razor Stryke Logo
Razor Stryke Logo
- Adobe Photoshop -
Night Lights (w/ A...
Night Lights (w/ A...
- Macromedia Flash -
Advanced Abstract ...
Advanced Abstract ...
- Maxon Cinema 4D -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 887 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1052 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1054 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1935 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1832 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14441 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2751 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2772 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3439 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2356 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2499 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2798 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673