Changeset 5922


Ignore:
Timestamp:
01/11/12 01:54:44 (5 months ago)
Author:
vain
Message:
  • removed formvalidation class, functionality is inside formelement and form
  • added, fixed and improved some unittests on forms
  • modified modulecontroller comments to enable ide hints
Location:
trunk
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/bootstrap/clansuite.application.php

    r5719 r5922  
    8989        #self::initialize_Logger(); 
    9090        self::initialize_UTF8(); 
    91         self::initialize_Debug();         
     91        self::initialize_Debug(); 
    9292        self::initialize_Timezone(); 
    9393        self::initialize_Eventdispatcher(); 
     
    142142        # 1. load the main clansuite configuration file 
    143143        $clansuite_cfg_cached = false; 
     144 
    144145        if(APC === true and apc_exists('clansuite.config')) 
    145146        { 
     
    159160 
    160161        # 2. Maintenance check 
    161         if( true === (bool) self::$config['maintenance']['maintenance'] ) 
     162        if( isset(self::$config['maintenance']['maintenance']) and 
     163            true === (bool) self::$config['maintenance']['maintenance'] ) 
    162164        { 
    163165            $token = false; 
     
    200202        ini_set('arg_separator.input', '&'); 
    201203        ini_set('arg_separator.output', '&'); 
     204        ini_set('default_charset', 'utf-8'); 
    202205        self::setMemoryLimit('32'); 
    203206        if(false === gc_enabled()) 
     
    249252    { 
    250253        /** 
    251              * 1) Shorthands and Syntax Declarations 
    252              */ 
    253  
    254             /** 
    255              * @var DS is a shorthand for DIRECTORY_SEPARATOR 
    256              */ 
    257             define('DS', DIRECTORY_SEPARATOR, false); 
    258  
    259             /** 
    260              * @var PS is a shorthand for PATH_SEPARATOR 
    261              */ 
    262             define('PS', PATH_SEPARATOR, false); 
    263  
    264             /** 
    265              * @var HTML Break + Carriage Return "<br />\r\n" 
    266              */ 
    267             define('NL', "<br />\r\n", false); 
    268  
    269             /** 
    270              * @var Carriage Return "\n" 
    271              */ 
    272             define('CR', "\n", false); 
    273  
    274             /** 
    275              * @var Carriage Return and Tabulator "\n\t" 
    276              */ 
    277             define('CRT', "\n\t", false); 
    278  
    279             /** 
    280              * 2) Path Assignments 
    281              *    ROOT and directories related to ROOT as absolute path shortcuts. 
    282              */ 
    283  
    284             /** 
    285              * ROOT is the APPLICATION PATH 
    286              * @var Purpose of ROOT is to provide the absolute path to the current working dir of clansuite 
    287              */ 
    288             define('ROOT', realpath(dirname(dirname(__DIR__))) . DS, false); 
    289  
    290             /** 
    291              * @var Root path of the cache directory (with trailing slash) 
    292              */ 
    293             define('ROOT_CACHE', ROOT . 'cache' . DS, false); 
    294  
    295             /** 
    296              * @var Root path of the config directory (with trailing slash) 
    297              */ 
    298             define('ROOT_CONFIG', ROOT . 'configuration' . DS, false); 
    299  
    300             /** 
    301              * @var Root path of the core directory (with trailing slash) 
    302              */ 
    303             define('ROOT_CORE', ROOT . 'core' . DS, false); 
    304  
    305             /** 
    306              * @var Root path of the languages directory (with trailing slash) 
    307              */ 
    308             define('ROOT_LANGUAGES', ROOT . 'languages' . DS, false); 
    309  
    310             /** 
    311              * @var Root path of the libraries directory (with trailing slash) 
    312              */ 
    313             define('ROOT_LIBRARIES', ROOT . 'libraries' . DS, false); 
    314  
    315             /** 
    316              * @var Root path of the logs directory (with trailing slash) 
    317              */ 
    318             define('ROOT_LOGS', ROOT . 'logs' . DS, false); 
    319  
    320             /** 
    321              * @var ROOT_MOD Root path of the modules directory (with trailing slash) 
    322              */ 
    323             define('ROOT_MOD', ROOT . 'modules' . DS, false); 
    324  
    325             /** 
    326              * @var Root path of the themes directory (with trailing slash) 
    327              */ 
    328             define('ROOT_THEMES', ROOT . 'themes' . DS, false); 
    329             define('ROOT_THEMES_BACKEND', ROOT_THEMES . 'backend' . DS, false); 
    330             define('ROOT_THEMES_FRONTEND', ROOT_THEMES . 'frontend' . DS, false); 
    331             define('ROOT_THEMES_CORE', ROOT_THEMES . 'core' . DS, false); 
    332  
    333             /** 
    334              * @var Root path of the upload directory (with trailing slash) 
    335              */ 
    336             define('ROOT_UPLOAD', ROOT . 'uploads' . DS, false); 
    337  
    338             /** 
    339              * @var Determine Type of Protocol for Webpaths (http/https) 
    340              */ 
    341             if(isset($_SERVER['HTTPS']) === true and strtolower($_SERVER['HTTPS']) == 'on') 
    342             { 
    343                 define('PROTOCOL', 'https://', false); 
    344             } 
    345             else 
    346             { 
    347                 define('PROTOCOL', 'http://', false); 
    348             } 
    349  
    350             /** 
    351              * @var SERVER_URL 
    352              */ 
    353                 define('SERVER_URL', PROTOCOL . $_SERVER['SERVER_NAME'], false); 
    354  
    355             /** 
    356              * @var WWW_ROOT is a complete www-path with servername from SERVER_URL, depending on os-system 
    357              */ 
    358             if(dirname($_SERVER['PHP_SELF']) === '\\') 
    359             { 
    360                 define('WWW_ROOT', SERVER_URL . '/', false); 
    361             } 
    362             else 
    363             { 
    364                 define('WWW_ROOT', SERVER_URL . dirname($_SERVER['PHP_SELF']) . '/', false); 
    365             } 
    366  
    367             /** 
    368              * @var WWW_ROOT_THEMES defines the themes folder 
    369              */ 
    370             define('WWW_ROOT_THEMES', WWW_ROOT . 'themes' . '/', false); 
    371             define('WWW_ROOT_THEMES_BACKEND', WWW_ROOT_THEMES . 'backend' . '/', false); 
    372             define('WWW_ROOT_THEMES_FRONTEND', WWW_ROOT_THEMES . 'frontend' . '/', false); 
    373             define('WWW_ROOT_THEMES_CORE', WWW_ROOT_THEMES . 'core' . '/', false); 
    374     } 
    375      
     254         * 1) Shorthands and Syntax Declarations 
     255         */ 
     256 
     257        /** 
     258         * @var DS is a shorthand for DIRECTORY_SEPARATOR 
     259         */ 
     260        define('DS', DIRECTORY_SEPARATOR, false); 
     261 
     262        /** 
     263         * @var PS is a shorthand for PATH_SEPARATOR 
     264         */ 
     265        define('PS', PATH_SEPARATOR, false); 
     266 
     267        /** 
     268         * @var NL is a shorthand for a HTML NEWLINE (HTML Break + Carriage Return) 
     269         */ 
     270        define('NL', "<br />\r\n", false); 
     271 
     272        /** 
     273         * @var Carriage Return "\n" 
     274         */ 
     275        define('CR', "\n", false); 
     276 
     277        /** 
     278         * @var Carriage Return and Tabulator "\n\t" 
     279         */ 
     280        define('CRT', "\n\t", false); 
     281 
     282        /** 
     283         * 2) Path Assignments 
     284         *    ROOT and directories related to ROOT as absolute path shortcuts. 
     285         */ 
     286 
     287        /** 
     288         * ROOT is the APPLICATION PATH 
     289         * @var Purpose of ROOT is to provide the absolute path to the current working dir of clansuite 
     290         */ 
     291        define('ROOT', realpath(dirname(dirname(__DIR__))) . DS, false); 
     292 
     293        /** 
     294         * @var Root path of the cache directory (with trailing slash) 
     295         */ 
     296        define('ROOT_CACHE', ROOT . 'cache' . DS, false); 
     297 
     298        /** 
     299         * @var Root path of the config directory (with trailing slash) 
     300         */ 
     301        define('ROOT_CONFIG', ROOT . 'configuration' . DS, false); 
     302 
     303        /** 
     304         * @var Root path of the core directory (with trailing slash) 
     305         */ 
     306        define('ROOT_CORE', ROOT . 'core' . DS, false); 
     307 
     308        /** 
     309         * @var Root path of the languages directory (with trailing slash) 
     310         */ 
     311        define('ROOT_LANGUAGES', ROOT . 'languages' . DS, false); 
     312 
     313        /** 
     314         * @var Root path of the libraries directory (with trailing slash) 
     315         */ 
     316        define('ROOT_LIBRARIES', ROOT . 'libraries' . DS, false); 
     317 
     318        /** 
     319         * @var Root path of the logs directory (with trailing slash) 
     320         */ 
     321        define('ROOT_LOGS', ROOT . 'logs' . DS, false); 
     322 
     323        /** 
     324         * @var ROOT_MOD Root path of the modules directory (with trailing slash) 
     325         */ 
     326        define('ROOT_MOD', ROOT . 'modules' . DS, false); 
     327 
     328        /** 
     329         * @var Root path of the themes directory (with trailing slash) 
     330         */ 
     331        define('ROOT_THEMES', ROOT . 'themes' . DS, false); 
     332        define('ROOT_THEMES_BACKEND', ROOT_THEMES . 'backend' . DS, false); 
     333        define('ROOT_THEMES_FRONTEND', ROOT_THEMES . 'frontend' . DS, false); 
     334        define('ROOT_THEMES_CORE', ROOT_THEMES . 'core' . DS, false); 
     335 
     336        /** 
     337         * @var Root path of the upload directory (with trailing slash) 
     338         */ 
     339        define('ROOT_UPLOAD', ROOT . 'uploads' . DS, false); 
     340 
     341        /** 
     342         * @var Determine Type of Protocol for Webpaths (http/https) 
     343         */ 
     344        if (isset($_SERVER['HTTPS']) === true and strtolower($_SERVER['HTTPS']) == 'on') 
     345        { 
     346            define('PROTOCOL', 'https://', false); 
     347        } 
     348        else 
     349        { 
     350            define('PROTOCOL', 'http://', false); 
     351        } 
     352 
     353        /** 
     354         * @var SERVER_URL 
     355         */ 
     356        define('SERVER_URL', PROTOCOL . $_SERVER['SERVER_NAME'], false); 
     357 
     358        /** 
     359         * @var WWW_ROOT is a complete www-path with servername from SERVER_URL, depending on os-system 
     360         */ 
     361        if (dirname($_SERVER['PHP_SELF']) === '\\') 
     362        { 
     363            define('WWW_ROOT', SERVER_URL . '/', false); 
     364        } 
     365        else 
     366        { 
     367            define('WWW_ROOT', SERVER_URL . dirname($_SERVER['PHP_SELF']) . '/', false); 
     368        } 
     369 
     370        /** 
     371         * @var WWW_ROOT_THEMES defines the themes folder 
     372         */ 
     373        define('WWW_ROOT_THEMES', WWW_ROOT . 'themes' . '/', false); 
     374        define('WWW_ROOT_THEMES_BACKEND', WWW_ROOT_THEMES . 'backend' . '/', false); 
     375        define('WWW_ROOT_THEMES_FRONTEND', WWW_ROOT_THEMES . 'frontend' . '/', false); 
     376        define('WWW_ROOT_THEMES_CORE', WWW_ROOT_THEMES . 'core' . '/', false); 
     377    } 
     378 
    376379    /** 
    377380     * Load Constants from APC 
  • trunk/core/modulecontroller.core.php

    r5837 r5922  
    6666 
    6767    /** 
    68      * @var object Clansuite_HttpResponse \Clansuite\Core\HttpResponse 
     68     * @var Clansuite_HttpResponse \Clansuite\Core\HttpResponse 
    6969     */ 
    7070    public $response = null; 
    7171 
    7272    /** 
    73      * @var object Clansuite_HttpRequest \Clansuite\Core\HttpRequest 
     73     * @var Clansuite_HttpRequest \Clansuite\Core\HttpRequest 
    7474     */ 
    7575    public $request = null; 
    7676 
    7777    /** 
    78      * @var object \Doctrine\ORM\EntityManager 
     78     * @var \Doctrine\ORM\EntityManager 
    7979     */ 
    8080    public $doctrine_em = null; 
  • trunk/core/viewhelper/form/form.core.php

    r5873 r5922  
    196196     * @var boolean 
    197197     */ 
    198     protected $formerror_flag = false; 
     198    protected $error = false; 
    199199 
    200200    /** 
     
    219219    protected $formgroups = array(); 
    220220 
    221     protected $errormessages_stack = array(); 
     221    /** 
     222     * Errormessages Stack 
     223     * 
     224     * @var array 
     225     */ 
     226    protected $errormessages = array(); 
    222227 
    223228    /** 
     
    460465    /** 
    461466     * Copy properties from object A to object B. 
    462      * *BadAssMethodWarning* 
    463467     * 
    464468     * @param object $object_to_copy The Object to copy the properties from. 
     
    468472    { 
    469473        $varArray = get_object_vars($object_to_copy); 
     474 
    470475        foreach($varArray as $key => $value) 
    471476        { 
     
    480485            } 
    481486        } 
     487 
    482488        unset($key, $value); 
    483489    } 
     
    871877     * @param $attributes array Attributes for the formelement. 
    872878     * @param $position integer The position number of this formelement (ordering) in the formelements stack. 0 is first element! 
     879     * 
    873880     * @return Clansuite_Form $this Form Object 
    874881     */ 
     
    943950    public function regenerateFormelementIdentifiers() 
    944951    { 
    945        $pos_lastpart = $pos = $firstpart = $id = ''; 
     952       $pos_lastpart = ''; 
     953       $pos = ''; 
     954       $firstpart = ''; 
     955       $id = ''; 
    946956 
    947957       $i = 0; 
     958 
    948959       foreach($this->formelements as $formelement) 
    949960       { 
     
    951962 
    952963           /** 
    953             *  the autogenerated id string has the following format 
    954             *  "type-formelement-id" 
    955             *  id is stripped off of the id string and the new id is appended. 
     964            * the autogenerated id string has the following abstract format: 
     965            * "type-formelement-id". it's exact string length is unknown. 
     966            * the last part separated by a minus (the id part) is stripped off 
     967            * of the string. 
    956968            */ 
    957969           $pos_lastpart = strrpos($id, '-') + 1; 
     
    959971           $firstpart = substr ($id, 0, -$pos); 
    960972 
    961            # append firstpart of old identifier with new int 
     973           # the new id is then appended to the remaining firstpart of the string 
    962974           $id = $firstpart .= $i; 
    963975 
     
    966978           $i++; 
    967979       } 
     980 
    968981       unset($i, $pos_lastpart, $pos, $firstpart, $id); 
    969982    } 
     
    11211134        { 
    11221135            # if not, redisplay the form (decorate with errors + render) 
    1123             $form->errors(); 
     1136            $this->addValidator($validator); 
     1137            $this->renderFormWithErrors(); 
    11241138 
    11251139        } 
     
    11271141        { 
    11281142            # success!! 
    1129             $form->success(); 
    1130         } 
     1143            $this->success(); 
     1144        } 
     1145    } 
     1146 
     1147    public function renderFormWithErrors() 
     1148    { 
     1149 
    11311150    } 
    11321151 
     
    11361155     * @return array containing all the form data. 
    11371156     */ 
    1138     protected function getDataArray() 
    1139     { 
    1140         $method = Clansuite_HttpRequest::getRequestMethod(); 
    1141  
    1142         if ($method === 'GET') 
    1143         { 
    1144             return Clansuite_HttpRequest::getGet(); 
    1145         } 
    1146  
    1147         if ($method === 'POST') 
    1148         { 
    1149             return Clansuite_HttpRequest::getPost(); 
    1150         } 
    1151     } 
    1152  
    1153     public function populate($data = null) 
    1154     { 
    1155         $this->setValues($data); 
    1156     } 
    1157  
     1157    protected function bind() 
     1158    { 
     1159 
     1160    } 
     1161 
     1162    /** 
     1163     * Set Values to Form 
     1164     * 
     1165     * An associative array is used to pre-populate form elements. 
     1166     * The keys of this array correspond with the element names. 
     1167     * 
     1168     * There are two use cases for this method: 
     1169     * 1) pre-filled form 
     1170     *    Some default values are set to the form, which then get altered by the user. 
     1171     * b) incomming post data 
     1172     *    Set the incomming POST data values are set to the form for validation. 
     1173     * 
     1174     * @param object|array $data Object or Array. If null (default), POST parameters are used. 
     1175     */ 
    11581176    public function setValues($data = null) 
    11591177    { 
    1160         # because $data might be an object, typecast $data to array 
     1178        # because $data might be an object, typecast $data object to array 
    11611179        if(is_object($data) === true) 
    11621180        { 
    11631181            $data = (array) $data; 
    11641182        } 
    1165         # fetch data from POST or GET 
     1183        # fetch data from POST 
    11661184        elseif(null === $data) 
    11671185        { 
    1168             $data = self::getDataArray(); 
    1169         } 
    1170  
    1171         # now we got an $data array to populate all the formelements with 
     1186            if ('POST' === Clansuite_HttpRequest::getRequestMethod() ) 
     1187            { 
     1188                $data = Clansuite_HttpRequest::getPost(); 
     1189            } 
     1190        } 
     1191 
     1192        # now we got an $data array to populate all the formelements with (setValue) 
    11721193        foreach($data as $key => $value) 
    11731194        { 
     
    11761197                $type = $formelement->getType(); 
    11771198 
    1178                 # skip certain formelements (buttons, etc.) from setValue() 
    1179                 # setting the value would change the visible "name" of these elements 
    1180                 if($type == 'submit' or $type == 'button' or $type == 'cancelbutton' or $type == 'resetbutton') 
     1199                /** 
     1200                 * Exclude some formelements from setValue(), e.g. buttons, etc. 
     1201                 * Setting the value would just change the visible "name" of these elements. 
     1202                 */ 
     1203                if(true === in_array($type, array('submit', 'button', 'cancelbutton', 'resetbutton'))) 
    11811204                { 
    11821205                    continue; 
    11831206                } 
    11841207 
    1185                 # data key and name of formelement have to match 
     1208                # data[key] and formelement[name] have to match 
    11861209                if($formelement->getName() == ucfirst($key)) 
    11871210                { 
     
    11921215    } 
    11931216 
     1217    /** 
     1218     * Get all values of the form. 
     1219     * 
     1220     * Or a bit more exact: 
     1221     * Get an array with the values of all the formelements objects which are registered to the form object. 
     1222     * The values are validated and ready for further processing, e.g. insert to model object. 
     1223     * 
     1224     * The validation is the big difference between using the $_POST array directly or indirectly. 
     1225     * 
     1226     * @return array 
     1227     */ 
    11941228    public function getValues() 
    11951229    { 
    1196         # return validates values, ready for model insert 
     1230        $values = array(); 
     1231 
     1232        foreach($this->formelements as $formelement) 
     1233        { 
     1234            /** 
     1235             * Create an associative array $value[id] => value 
     1236             */ 
     1237            $values[$formelement->getId()] = $formelement->getValue(); 
     1238        } 
     1239 
     1240        # return validated values, ready for further processing (model insert) 
     1241        return $values; 
    11971242    } 
    11981243 
     
    12051250    /** 
    12061251     * Is a shortcut/proxy/convenience method for addDecorator() 
    1207      * <strong>WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM</strong> 
     1252     * <strong>WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM</strong> 
    12081253     * 
    12091254     * @see $this->addDecorator() 
     
    12321277    /** 
    12331278     * Adds a decorator to the form 
    1234      * <strong>WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM</strong> 
     1279     * <strong>WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM</strong> 
    12351280     * 
    12361281     * @example 
     
    12701315        } 
    12711316 
    1272         # WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
     1317        # WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
    12731318        # We dont return $this here, because $this would be the FORM. 
    12741319        # Insted the decorator is returned, to apply some properties. 
     
    14731518     * @see $this->addFormelementDecorator() 
    14741519     * 
    1475      * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
     1520     * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
    14761521     * @return Clansuite_Formdecorator object 
    14771522     */ 
     
    14941539     * If no position is given, it defaults to the last formelement in the stack of formelements. 
    14951540     * 
    1496      * <strong>WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM</strong> 
     1541     * <strong>WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM</strong> 
    14971542     * 
    14981543     * @example 
     
    15121557 
    15131558        $formelement_object = ''; 
     1559 
    15141560        if(false === is_object($formelement_pos_name_obj)) 
    15151561        { 
     
    15181564 
    15191565        # add the decorator 
    1520         # WATCH IT! this is a forwarding call to formelement.core.php->addDecorator() 
     1566        # WATCH OUT! this is a forwarding call to formelement.core.php->addDecorator() 
    15211567        return $formelement_object->addDecorator($decorator); 
    15221568    } 
     
    15671613    public function addValidator($validator) 
    15681614    { 
    1569  
     1615        if(is_object($validator) and is_a($validator, Clansuite_Validator_Interface)) 
     1616        { 
     1617 
     1618        } 
    15701619 
    15711620        return $this; 
     
    15931642        } 
    15941643 
    1595         if($this->hasErrors() === true) 
     1644        if($this->getErrorState() === true) 
    15961645        { 
    15971646            # form has errors and does not validate 
    15981647            return false; 
     1648        } 
     1649        else 
     1650        { 
     1651            return true; 
    15991652        } 
    16001653    } 
     
    16061659     */ 
    16071660 
     1661     /** 
     1662      * Sets the error state of the form (formHasError). 
     1663      * 
     1664      * @param boolean $boolean 
     1665      */ 
    16081666     public function setErrorState($boolean = true) 
    16091667     { 
    1610         $this->form_has_error_flag = $boolean; 
     1668        $this->error = $boolean; 
    16111669     } 
    16121670 
     1671     /** 
     1672      * Returns the error state of the form. 
     1673      * 
     1674      * @return boolean False, if form has an error. True, otherwise. 
     1675      */ 
    16131676     public function getErrorState() 
    16141677     { 
    1615         return $this->form_has_error_flag; 
    1616      } 
    1617  
    1618      public function hasErrors() 
    1619      { 
    1620         return $this->form_has_error_flag; 
     1678        return $this->error; 
    16211679     } 
    16221680 
    16231681     public function addErrormessage($errormessage) 
    16241682     { 
    1625         $this->errormessages_stack[] = $errormessage; 
     1683        $this->errormessages[] = $errormessage; 
    16261684     } 
    16271685 
    16281686     public function addErrormessages(array $errormessages) 
    16291687     { 
    1630         $this->errormessages_stack = $errormessages; 
     1688        $this->errormessages = $errormessages; 
    16311689     } 
    16321690 
    16331691     public function resetErrormessages() 
    16341692     { 
    1635         $this->errormessages_stack = array(); 
     1693        $this->errormessages = array(); 
    16361694     } 
    16371695 
    16381696     public function getErrormessages() 
    16391697     { 
    1640         return $this->errormessages_stack; 
     1698        return $this->errormessages; 
    16411699     } 
    16421700 
  • trunk/core/viewhelper/form/formdecorators/form/form.form.php

    r5246 r5922  
    3939class Clansuite_Form_Decorator_Form extends Clansuite_Form_Decorator 
    4040{ 
    41  
    4241    /** 
    4342     * Name of this decorator 
     
    162161        # put all the pieces of html together 
    163162        $html_form_content = $this->openOpenFormTag().              # <form 
    164                              $this->getFormTagAttributesAsHTML().   #  .... 
     163                             $this->getFormTagAttributesAsHTML().   #  id/method/action/... 
    165164                             $this->closeOpenFormTag().             # > 
    166165                             $this->addHeading().                   # heading 
  • trunk/core/viewhelper/form/formelement.core.php

    r5544 r5922  
    7070     * @var formelement_validation_errors 
    7171     */ 
    72     protected $formelement_validation_errors = array(); 
     72    protected $validation_errors = array(); 
    7373 
    7474    /** 
     
    202202 
    203203    /** 
    204      * Return the value (escaped) 
     204     * Return the (escaped!) value of the formelement. 
    205205     * 
    206206     * @return string Escaped string 
     
    224224 
    225225    /** 
    226      * Returns the value (unescaped) 
     226     * Returns the (unescaped!) value 
    227227     * 
    228228     * @return string Unescaped string 
     
    298298 
    299299    /** 
    300      * Returns boolean true if this formelement is required. 
    301      * Use this in conditionals. 
     300     * This method provides a shortcut for checking if an formelement is required. 
     301     * You might use this in conditional checks. 
    302302     * 
    303303     * @return boolean True if formelement is required, false if not. 
     
    318318 
    319319    /** 
    320      * Returns required status. 
    321      * 
    322      * @return boolean True if formelement is required, false if not. 
    323      */ 
    324     public function getRequired() 
    325     { 
    326         return $this->required; 
    327     } 
    328  
    329     /** 
    330      * Set required status for this formelement. 
    331      * 
    332      * @param boolean $required Set required status. Defaults to true. 
    333      * @return Clansuite_Formelement 
    334      */ 
    335     public function setRequired($required = null) 
    336     { 
    337         if($required === null) 
    338         { 
    339             $this->required = true; 
    340         } 
    341         else 
    342         { 
    343             $this->required = (bool) $required; 
    344         } 
     320     * Set required state for the formelement. 
     321     * A formelement is required, when the user is expected to (must) enter data into the formelement. 
     322     * 
     323     * @param boolean $required Set required state. Defaults to true. 
     324     * @return Clansuite_Formelement 
     325     */ 
     326    public function setRequired($required = true) 
     327    { 
     328        $this->required = ($required === true) ? true : false; 
    345329 
    346330        return $this; 
     
    482466 
    483467    /** 
     468     * expect / setRules 
     469     * 
     470     * set validation rules 
     471     * $rules['input-firstname']  = "required"; 
     472     * $rules['input-email']      = "required, email"; 
     473     */ 
     474    public function expect($rule) 
     475    { 
     476        if(false === is_string($rule)) 
     477        { 
     478            throw new Clansuite_Exception('Parameter $rule must be of type string.'); 
     479        } 
     480 
     481        $rules = explode(',', $rule); 
     482 
     483        foreach($rules as $rule) 
     484        { 
     485            $this->addValidator($rule); 
     486        } 
     487    } 
     488 
     489    /** 
    484490     * addValidator 
    485491     * 
    486492     * Is a shortcut/proxy/convenience method for addValidator() 
    487      * @see $this->addValidator() 
    488      * 
    489      * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
     493     * 
     494     * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
    490495     * @return Clansuite_Formelement_Validator 
    491496     */ 
    492497    public function addValidator($validator) 
    493498    { 
    494         return $this->addValidator($decorators); 
    495     } 
    496  
    497     /** 
    498      * Setter method for a validator 
    499      * validators are stored into an array (multiple validators for one formelement). 
     499        if(false === is_object($validator)) 
     500        { 
     501 
     502        } 
     503 
     504        $this->setValidator($validator); 
     505 
     506        return $this; 
     507    } 
     508 
     509    /** 
     510     * Setter method for a validator. 
     511     * The Validator is stored into the validators array. 
     512     * So a formelement might have multiple validators. 
    500513     * 
    501514     * @param Clansuite_Validator $validator Accepts a Clansuite_Validator Object that has to implement Clansuite_Validator_Interface. 
    502515     * @return Clansuite_Formelement 
    503516     */ 
    504     public function setValidator(Clansuite_Form_Validation_Interface $validator) 
     517    public function setValidator(/*Clansuite_Formelement_Validates_Interface*/ $validator) 
    505518    { 
    506519        $this->validators[] = $validator; 
     
    510523 
    511524    /** 
    512      * validation method for a single formelement 
    513      * it processes all registered validators for this formelement. 
     525     * The validation method processes all registered validators of a sinngle formelement. 
    514526     * 
    515527     * @see $validators array 
     
    529541            else 
    530542            { 
    531                 # raise error flag 
    532                 $formelement_validation_error = true; 
    533  
    534                 # fetch error from the validator to the formelement 
     543                # raise the error flag on the formelement 
     544                $this->setError(true); 
     545 
     546                # and transfer error message from the validator to the formelement 
    535547                $this->addError($validator->getError()); 
     548 
    536549                return false; 
    537550            } 
     
    546559    public function addError($validation_error) 
    547560    { 
    548         $this->formelement_validation_errors[] = $validation_error; 
    549     } 
     561        $this->validation_errors[] = $validation_error; 
     562    } 
     563 
     564    /** 
     565      * Sets the error state of the form (formHasError). 
     566      * 
     567      * @param boolean $boolean 
     568      */ 
     569     public function setError($boolean = true) 
     570     { 
     571        $this->error = $boolean; 
     572     } 
     573 
     574     /** 
     575      * Returns the error state of the form. 
     576      * 
     577      * @return boolean False, if form has an error. True, otherwise. 
     578      */ 
     579     public function hasError() 
     580     { 
     581        return $this->error; 
     582     } 
    550583 
    551584    /** 
     
    598631     * @see $this->addDecorator() 
    599632     * 
    600      * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
     633     * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
    601634     * @return Clansuite_Formelement_Decorator 
    602635     */ 
     
    612645     * $form->addDecorator('fieldset')->setLegend('legendname'); 
    613646     * 
    614      * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM OBJECT 
     647     * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM OBJECT 
    615648     * @return Clansuite_Formelement_Decorator 
    616649     */ 
     
    639672                    $decoratorname = $decorator->name; 
    640673 
    641                     # WATCH IT! RECURSION! 
     674                    # WATCH OUT! RECURSION! 
    642675                    $this->addDecorator($decorator); 
    643676                } 
     
    665698        } 
    666699 
    667         # WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
     700        # WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 
    668701        # We dont return $this here, because $this would be the formelement. 
    669702        # Insted the decorator is returned, to apply some properties. 
  • trunk/core/viewhelper/form/formelements/input.form.php

    r5544 r5922  
    5353{ 
    5454    /** 
    55      * input type 
    56      * 
    57      * @var int 
     55     * The formelement input type, e.g. 
     56     * text, password, checkbox, radio, submit, reset, file, hidden, image, button. 
     57     * 
     58     * @var string 
    5859     */ 
    5960    public $type; 
     
    108109     */ 
    109110    public $description; 
    110      
     111 
    111112    /** 
    112113     * A regular expression pattern, e.g. [A-Za-z]+\d+ 
     
    115116     */ 
    116117    public $pattern; 
    117      
    118     /**  
     118 
     119    /** 
    119120     * String value for the placeholder attribute 
    120121     * <input placeholder="some placeholder"> 
     
    132133    { 
    133134        $this->placeholder = $placeholder; 
    134      
     135 
    135136        return $this; 
    136137    } 
    137138 
     139    /** 
     140     * Get Placeholder <input placeholder="some placeholder"> 
     141     * 
     142     * @return type 
     143     */ 
    138144    public function getPlaceholder() 
    139145    { 
     
    164170    { 
    165171        $this->additional_attr_text = $additional_attr_text; 
     172 
    166173        return $this; 
    167174    } 
    168175 
    169176    /** 
    170      * generates html code of element 
     177     * Renders the html code of the input element. 
     178     * 
     179     * @return string 
    171180     */ 
    172181    public function render() 
  • trunk/tests/unittests/core/viewhelper/form/form.core.php

    r5875 r5922  
    156156    public function testCopyObjectProperties() 
    157157    { 
    158         $object_a = new stdClass(); 
    159         $object_a->attribute_string = 'value_of_attr_a'; 
    160         $object_a->attribute_int = 9; 
    161         $object_a->attribute_bool = true; 
    162         $object_a->attribute_array = array('key' => 'value'); 
    163  
    164         $object_b = new stdClass(); 
    165  
    166         $this->form->copyObjectProperties($object_a, $object_b); 
    167  
    168         $this->assertIdentical($object_a, $object_b); 
    169         $this->assertTrue($object_a->attribute_string, 'value_of_attr_a'); 
    170         $this->assertTrue($object_a->attribute_int, 9); 
    171         $this->assertTrue($object_a->attribute_bool, true); 
    172         $this->assertTrue($object_a->attribute_array['key'], 'value'); 
     158        # prefilled object 
     159        $from_object_a = new stdClass(); 
     160        $from_object_a->attribute_string = 'value_of_attr_a'; 
     161        $from_object_a->attribute_int = 9; 
     162        $from_object_a->attribute_bool = true; 
     163        $from_object_a->attribute_array = array('key' => 'value'); 
     164 
     165        # empty target object 
     166        $to_object_b = new stdClass(); 
     167 
     168        $this->form->copyObjectProperties($from_object_a, $to_object_b); 
     169 
     170        $this->assertIdentical($from_object_a, $to_object_b); 
     171        $this->assertTrue($to_object_b->attribute_string, 'value_of_attr_a'); 
     172        $this->assertTrue($to_object_b->attribute_int, 9); 
     173        $this->assertTrue($to_object_b->attribute_bool, true); 
     174        $this->assertTrue($to_object_b->attribute_array['key'], 'value'); 
    173175    } 
    174176 
     
    577579    } 
    578580 
    579     public function testPopulate() 
     581    public function testsetValues_DataArrayPassedToMethod() 
    580582    { 
    581583        # create multiselect "Snacks" with three options 
     
    587589        $data = array('snacks' => array('cola', 'popcorn')); 
    588590 
    589         $this->form->populate($data); 
     591        $this->form->setValues($data); 
    590592 
    591593        $snacks_array = $this->form->getElementByName('Snacks')->getValue(); 
     
    595597    } 
    596598 
    597     public function testsetValues() 
    598     { 
    599         # create multiselect "Snacks" with three options 
    600         $this->form->addElement('multiselect')->setName('Snacks')->setOptions( 
    601             array('cola' => 'Cola', 'popcorn' => 'Popcorn', 'peanuts' => 'Peanuts') 
     599    public function testgetValues() 
     600    { 
     601        $this->form->addElement('textarea', array('value' => 'Some Text Inside The First Textarea')); 
     602        $this->form->addElement('textarea', array('value' => 'More Text Inside The Second Textarea')); 
     603 
     604        $values = $this->form->getValues(); 
     605 
     606        $this->assertTrue(is_array($values)); 
     607        $this->assertIdentical(count($values), 2); 
     608 
     609        $expected_values = array ( 
     610            'textarea-formelement-0' => 'Some Text Inside The First Textarea', 
     611            'textarea-formelement-1' => 'More Text Inside The Second Textarea' 
    602612        ); 
    603613 
    604         # two options were selected (array is incomming via post) 
    605         $data = array('snacks' => array('cola', 'popcorn')); 
    606  
    607         $this->form->setValues($data); 
    608  
    609         $snacks_array = $this->form->getElementByName('Snacks')->getValue(); 
    610         $this->assertIdentical(count($snacks_array), 2); 
    611         $this->assertIdentical($snacks_array[0], 'cola'); 
    612         $this->assertIdentical($snacks_array[1], 'popcorn'); 
    613     } 
    614  
    615     public function testgetValues() 
    616     { 
    617         #$values = $this->form->getValues(); 
    618         #$this->assertTrue(is_array($values)); 
     614        $this->assertIdentical($values, $expected_values); 
    619615    } 
    620616 
     
    730726                'This test has not been implemented yet.' 
    731727        ); 
    732     } 
     728    }*/ 
    733729 
    734730    public function testValidateForm() 
    735731    { 
     732        $this->form->addElement('textarea')->setRequired()->expect('required, string, maxlength=100'); 
     733 
     734 
     735        $this->form->validateForm(); 
     736 
    736737        // Remove the following lines when you implement this test. 
    737738        $this->markTestIncomplete( 
    738739                'This test has not been implemented yet.' 
    739740        ); 
    740     }*/ 
     741    } 
     742 
     743    public function testsetRequired() 
     744    { 
     745        $this->form->addElement('textarea')->setName('Textarea-A')->setRequired(); 
     746 
     747        $formelement = $this->form->getElementByName('Textarea-A'); 
     748        $this->assertTrue($formelement->required); 
     749        $this->assertTrue($formelement->isRequired()); 
     750    } 
     751 
     752    public function testIsRequired() 
     753    { 
     754        $this->form->addElement('textarea')->setName('Textarea-A')->setRequired(); 
     755        $formelement = $this->form->getElementByName('Textarea-A'); 
     756        $this->assertTrue($formelement->required); 
     757        $this->assertTrue($formelement->isRequired()); 
     758    } 
    741759 
    742760    public function testsetErrorState() 
    743761    { 
    744762        $this->form->setErrorState(true); 
     763        $this->assertTrue($this->form->error); 
    745764        $this->assertTrue($this->form->getErrorState()); 
    746765    } 
     
    749768    { 
    750769        $this->form->setErrorState(true); 
     770        $this->assertTrue($this->form->error); 
    751771        $this->assertTrue($this->form->getErrorState()); 
    752772 
    753773        $this->form->setErrorState(false); 
     774        $this->assertFalse($this->form->error); 
    754775        $this->assertFalse($this->form->getErrorState()); 
    755     } 
    756  
    757     public function testhasErrors() 
    758     { 
    759         $this->form->setErrorState(true); 
    760         $this->assertTrue($this->form->hasErrors()); 
    761  
    762         $this->form->setErrorState(false); 
    763         $this->assertFalse($this->form->hasErrors()); 
    764776    } 
    765777 
Note: See TracChangeset for help on using the changeset viewer.