Ignore:
Timestamp:
Dec 18, 2005 12:16:03 AM (18 years ago)
Author:
scdev
Message:

detabbed all files ;P

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FormValidator.inc.php

    r41 r42  
    11<?php
    22/**
    3  * FormValidator.inc.php 
     3 * FormValidator.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    55 *
     
    2525class FormValidator
    2626{
    27    
     27
    2828    /**
    2929     * Array filling with errors. The key will be the name of the form where
     
    3131     */
    3232    var $errors = array();
    33    
     33
    3434    /**
    3535     * Return the current list of errors.
     
    4343        return $this->errors;
    4444    }
    45    
     45
    4646    /**
    4747     * Add an error to the errors stack.
     
    6464        );
    6565    }
    66    
     66
    6767    /**
    6868     * Check whether any errors have been triggered.
     
    7070     * @param  string $form_name the name of the incoming form variable
    7171     *
    72      * @return bool   true if any errors were found, or if found for 
     72     * @return bool   true if any errors were found, or if found for
    7373     *                a variable of $form_name, false otherwise
    7474     */
     
    7878            foreach ($this->errors as $err) {
    7979                if ($err['name'] == $form_name) {
    80                     return true;   
     80                    return true;
    8181                }
    8282            }
     
    115115                        echo '<div class="error">' . $err['message'] . '</div>';
    116116                        break;
    117            
     117
    118118                    case MSG_WARNING:
    119119                        echo '<div class="warning">' . $err['message'] . '</div>';
    120120                        break;
    121            
     121
    122122                    case MSG_SUCCESS:
    123123                        echo '<div class="success">' . $err['message'] . '</div>';
    124124                        break;
    125            
     125
    126126                    case MSG_NOTICE:
    127127                    default:
     
    134134        }
    135135    }
    136    
     136
    137137    /**
    138138     * If this form has an error, print an error marker like "<<".
     
    164164    function notEmpty($form_name, $msg='')
    165165    {
    166    
     166
    167167        $val = trim(getFormData($form_name));
    168168        if ($val != '') {
     
    184184    function isEmpty($form_name, $msg='')
    185185    {
    186    
     186
    187187        $val = trim(getFormData($form_name));
    188188        if ($val == '') {
     
    255255    /**
    256256     * Check whether input is a float. Don't just use is_float() because the
    257      * data coming from the user is *really* a string. Integers will also 
     257     * data coming from the user is *really* a string. Integers will also
    258258     * pass this test.
    259259     *
     
    293293        }
    294294    }
    295    
     295
    296296    /**
    297297     * Check whether input matches the specified perl regular expression
    298      * pattern. 
     298     * pattern.
    299299     *
    300300     * @param  string $form_name the name of the incoming form variable
     
    325325        }
    326326    }
    327    
     327
    328328    /**
    329329     * Tests if the string length is between specified values. Whitespace excluded for min.
     
    339339    {
    340340        $val = getFormData($form_name);
    341        
     341
    342342        if (strlen(trim($val)) < $min || strlen($val) > $max) {
    343343            $this->addError($form_name, $msg);
     
    375375    /**
    376376     * Validates an email address based on the recommendations in RFC 3696.
    377      * Is more loose than restrictive, to allow the many valid variants of 
     377     * Is more loose than restrictive, to allow the many valid variants of
    378378     * email addresses while catching the most common mistakes.
    379379     * http://www.faqs.org/rfcs/rfc822.html
     
    403403            return false;
    404404        }
    405        
     405
    406406        // We have a match! Here are the captured subpatterns, on which further tests are run.
    407407        $local = $e_parts[2];
     
    415415            return false;
    416416        }
    417        
     417
    418418        // Check domain exists: It's a domain if ip2long fails; Checkdnsrr ensures a MX record exists; Gethostbyname() ensures the domain exists.
    419419        if (ip2long($domain) == '-1' && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) {
     
    422422            return false;
    423423        }
    424        
     424
    425425        return true;
    426426    }
     
    431431//             return false;
    432432//         }
    433 //         
     433//
    434434//         // Test email address format.
    435435//         if ($allow_fullname) {
     
    444444//             }
    445445//         }
    446 //         
     446//
    447447//         // Test length.
    448448//         if (!$this->stringLength($form_name, 0, 255, sprintf(_("<strong>Email address</strong> must contain less than 256 characters."), $email))) {
     
    450450//             return false;
    451451//         }
    452 //         
     452//
    453453//         // Check domain exists and has valid MX record.
    454454//         preg_match('/^[^<>@]*<?[^\s@\[\]<>()]+\@([A-Za-z0-9.-]+\.[A-Za-z]{2,5})>?$/i', $email, $matches);
     
    460460//             }
    461461//         }
    462 //         
     462//
    463463//         return true;
    464464//     }
     
    476476    {
    477477        $phone = getFormData($form_name);
    478        
     478
    479479        return $this->checkRegex($form_name, '/^[0-9 +().-]*$/', true, sprintf(_("The phone number <strong>%s</strong> is not valid."), $phone))
    480480        && $this->stringLength($form_name, 0, 25, sprintf(_("The phone number <strong>%s</strong> is too long"), $phone));
     
    499499        }
    500500    }
    501    
    502    
     501
     502
    503503    /**
    504504     * Verifies credit card number.
     
    515515            $cc_num = getFormData($form_name);
    516516        }
    517        
     517
    518518        if ('' == $cc_num) {
    519519            return false;
    520520        }
    521        
     521
    522522        // Innocent until proven guilty
    523523        $card_is_valid = true;
    524    
     524
    525525        // Get rid of any non-digits
    526526        $cc_num = preg_replace('/[^\d]/', '', $cc_num);
    527    
     527
    528528        // Perform card-specific checks, if applicable
    529529        switch (strtolower($cc_type)) {
     
    558558                break;
    559559        }
    560    
     560
    561561        // The Luhn formula works right to left, so reverse the number.
    562562        $cc_num = strrev($cc_num);
    563        
     563
    564564        $luhn_total = 0;
    565565
     
    573573                $digit *= 2;
    574574            }
    575    
     575
    576576            //  If the result is two digits, add them.
    577577            if (strlen($digit) == 2) {
    578578                $digit = substr($digit,0,1) + substr($digit,1,1);
    579579            }
    580    
     580
    581581            //  Add the current digit to the $luhn_total.
    582582            $luhn_total += $digit;
    583583        }
    584    
     584
    585585        // If it passed (or bypassed) the card-specific check and the Total is evenly divisible by 10, it's cool!
    586586        if ($card_is_valid && $luhn_total % 10 == 0) {
     
    609609        }
    610610    }
    611    
     611
    612612} // THE END
    613613
Note: See TracChangeset for help on using the changeset viewer.