Changeset 5922
- Timestamp:
- 01/11/12 01:54:44 (5 months ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 7 edited
-
core/bootstrap/clansuite.application.php (modified) (5 diffs)
-
core/modulecontroller.core.php (modified) (1 diff)
-
core/viewhelper/form/form.core.php (modified) (25 diffs)
-
core/viewhelper/form/formdecorators/form/form.form.php (modified) (2 diffs)
-
core/viewhelper/form/formelement.core.php (modified) (13 diffs)
-
core/viewhelper/form/formelements/input.form.php (modified) (5 diffs)
-
core/viewhelper/form/formvalidation.core.php (deleted)
-
core/viewhelper/form/formvalidators (deleted)
-
tests/unittests/core/viewhelper/form/form.core.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/bootstrap/clansuite.application.php
r5719 r5922 89 89 #self::initialize_Logger(); 90 90 self::initialize_UTF8(); 91 self::initialize_Debug(); 91 self::initialize_Debug(); 92 92 self::initialize_Timezone(); 93 93 self::initialize_Eventdispatcher(); … … 142 142 # 1. load the main clansuite configuration file 143 143 $clansuite_cfg_cached = false; 144 144 145 if(APC === true and apc_exists('clansuite.config')) 145 146 { … … 159 160 160 161 # 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'] ) 162 164 { 163 165 $token = false; … … 200 202 ini_set('arg_separator.input', '&'); 201 203 ini_set('arg_separator.output', '&'); 204 ini_set('default_charset', 'utf-8'); 202 205 self::setMemoryLimit('32'); 203 206 if(false === gc_enabled()) … … 249 252 { 250 253 /** 251 * 1) Shorthands and Syntax Declarations252 */253 254 /**255 * @var DS is a shorthand for DIRECTORY_SEPARATOR256 */257 define('DS', DIRECTORY_SEPARATOR, false);258 259 /**260 * @var PS is a shorthand for PATH_SEPARATOR261 */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 Assignments281 * ROOT and directories related to ROOT as absolute path shortcuts.282 */283 284 /**285 * ROOT is the APPLICATION PATH286 * @var Purpose of ROOT is to provide the absolute path to the current working dir of clansuite287 */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 else346 {347 define('PROTOCOL', 'http://', false);348 }349 350 /**351 * @var SERVER_URL352 */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-system357 */358 if(dirname($_SERVER['PHP_SELF']) === '\\')359 {360 define('WWW_ROOT', SERVER_URL . '/', false);361 }362 else363 {364 define('WWW_ROOT', SERVER_URL . dirname($_SERVER['PHP_SELF']) . '/', false);365 }366 367 /**368 * @var WWW_ROOT_THEMES defines the themes folder369 */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 376 379 /** 377 380 * Load Constants from APC -
trunk/core/modulecontroller.core.php
r5837 r5922 66 66 67 67 /** 68 * @var objectClansuite_HttpResponse \Clansuite\Core\HttpResponse68 * @var Clansuite_HttpResponse \Clansuite\Core\HttpResponse 69 69 */ 70 70 public $response = null; 71 71 72 72 /** 73 * @var objectClansuite_HttpRequest \Clansuite\Core\HttpRequest73 * @var Clansuite_HttpRequest \Clansuite\Core\HttpRequest 74 74 */ 75 75 public $request = null; 76 76 77 77 /** 78 * @var object\Doctrine\ORM\EntityManager78 * @var \Doctrine\ORM\EntityManager 79 79 */ 80 80 public $doctrine_em = null; -
trunk/core/viewhelper/form/form.core.php
r5873 r5922 196 196 * @var boolean 197 197 */ 198 protected $ formerror_flag= false;198 protected $error = false; 199 199 200 200 /** … … 219 219 protected $formgroups = array(); 220 220 221 protected $errormessages_stack = array(); 221 /** 222 * Errormessages Stack 223 * 224 * @var array 225 */ 226 protected $errormessages = array(); 222 227 223 228 /** … … 460 465 /** 461 466 * Copy properties from object A to object B. 462 * *BadAssMethodWarning*463 467 * 464 468 * @param object $object_to_copy The Object to copy the properties from. … … 468 472 { 469 473 $varArray = get_object_vars($object_to_copy); 474 470 475 foreach($varArray as $key => $value) 471 476 { … … 480 485 } 481 486 } 487 482 488 unset($key, $value); 483 489 } … … 871 877 * @param $attributes array Attributes for the formelement. 872 878 * @param $position integer The position number of this formelement (ordering) in the formelements stack. 0 is first element! 879 * 873 880 * @return Clansuite_Form $this Form Object 874 881 */ … … 943 950 public function regenerateFormelementIdentifiers() 944 951 { 945 $pos_lastpart = $pos = $firstpart = $id = ''; 952 $pos_lastpart = ''; 953 $pos = ''; 954 $firstpart = ''; 955 $id = ''; 946 956 947 957 $i = 0; 958 948 959 foreach($this->formelements as $formelement) 949 960 { … … 951 962 952 963 /** 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. 956 968 */ 957 969 $pos_lastpart = strrpos($id, '-') + 1; … … 959 971 $firstpart = substr ($id, 0, -$pos); 960 972 961 # append firstpart of old identifier with new int973 # the new id is then appended to the remaining firstpart of the string 962 974 $id = $firstpart .= $i; 963 975 … … 966 978 $i++; 967 979 } 980 968 981 unset($i, $pos_lastpart, $pos, $firstpart, $id); 969 982 } … … 1121 1134 { 1122 1135 # if not, redisplay the form (decorate with errors + render) 1123 $form->errors(); 1136 $this->addValidator($validator); 1137 $this->renderFormWithErrors(); 1124 1138 1125 1139 } … … 1127 1141 { 1128 1142 # success!! 1129 $form->success(); 1130 } 1143 $this->success(); 1144 } 1145 } 1146 1147 public function renderFormWithErrors() 1148 { 1149 1131 1150 } 1132 1151 … … 1136 1155 * @return array containing all the form data. 1137 1156 */ 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 */ 1158 1176 public function setValues($data = null) 1159 1177 { 1160 # because $data might be an object, typecast $data to array1178 # because $data might be an object, typecast $data object to array 1161 1179 if(is_object($data) === true) 1162 1180 { 1163 1181 $data = (array) $data; 1164 1182 } 1165 # fetch data from POST or GET1183 # fetch data from POST 1166 1184 elseif(null === $data) 1167 1185 { 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) 1172 1193 foreach($data as $key => $value) 1173 1194 { … … 1176 1197 $type = $formelement->getType(); 1177 1198 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'))) 1181 1204 { 1182 1205 continue; 1183 1206 } 1184 1207 1185 # data key and name of formelementhave to match1208 # data[key] and formelement[name] have to match 1186 1209 if($formelement->getName() == ucfirst($key)) 1187 1210 { … … 1192 1215 } 1193 1216 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 */ 1194 1228 public function getValues() 1195 1229 { 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; 1197 1242 } 1198 1243 … … 1205 1250 /** 1206 1251 * 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> 1208 1253 * 1209 1254 * @see $this->addDecorator() … … 1232 1277 /** 1233 1278 * 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> 1235 1280 * 1236 1281 * @example … … 1270 1315 } 1271 1316 1272 # WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM1317 # WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 1273 1318 # We dont return $this here, because $this would be the FORM. 1274 1319 # Insted the decorator is returned, to apply some properties. … … 1473 1518 * @see $this->addFormelementDecorator() 1474 1519 * 1475 * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM1520 * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 1476 1521 * @return Clansuite_Formdecorator object 1477 1522 */ … … 1494 1539 * If no position is given, it defaults to the last formelement in the stack of formelements. 1495 1540 * 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> 1497 1542 * 1498 1543 * @example … … 1512 1557 1513 1558 $formelement_object = ''; 1559 1514 1560 if(false === is_object($formelement_pos_name_obj)) 1515 1561 { … … 1518 1564 1519 1565 # 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() 1521 1567 return $formelement_object->addDecorator($decorator); 1522 1568 } … … 1567 1613 public function addValidator($validator) 1568 1614 { 1569 1615 if(is_object($validator) and is_a($validator, Clansuite_Validator_Interface)) 1616 { 1617 1618 } 1570 1619 1571 1620 return $this; … … 1593 1642 } 1594 1643 1595 if($this-> hasErrors() === true)1644 if($this->getErrorState() === true) 1596 1645 { 1597 1646 # form has errors and does not validate 1598 1647 return false; 1648 } 1649 else 1650 { 1651 return true; 1599 1652 } 1600 1653 } … … 1606 1659 */ 1607 1660 1661 /** 1662 * Sets the error state of the form (formHasError). 1663 * 1664 * @param boolean $boolean 1665 */ 1608 1666 public function setErrorState($boolean = true) 1609 1667 { 1610 $this-> form_has_error_flag= $boolean;1668 $this->error = $boolean; 1611 1669 } 1612 1670 1671 /** 1672 * Returns the error state of the form. 1673 * 1674 * @return boolean False, if form has an error. True, otherwise. 1675 */ 1613 1676 public function getErrorState() 1614 1677 { 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; 1621 1679 } 1622 1680 1623 1681 public function addErrormessage($errormessage) 1624 1682 { 1625 $this->errormessages _stack[] = $errormessage;1683 $this->errormessages[] = $errormessage; 1626 1684 } 1627 1685 1628 1686 public function addErrormessages(array $errormessages) 1629 1687 { 1630 $this->errormessages _stack= $errormessages;1688 $this->errormessages = $errormessages; 1631 1689 } 1632 1690 1633 1691 public function resetErrormessages() 1634 1692 { 1635 $this->errormessages _stack= array();1693 $this->errormessages = array(); 1636 1694 } 1637 1695 1638 1696 public function getErrormessages() 1639 1697 { 1640 return $this->errormessages _stack;1698 return $this->errormessages; 1641 1699 } 1642 1700 -
trunk/core/viewhelper/form/formdecorators/form/form.form.php
r5246 r5922 39 39 class Clansuite_Form_Decorator_Form extends Clansuite_Form_Decorator 40 40 { 41 42 41 /** 43 42 * Name of this decorator … … 162 161 # put all the pieces of html together 163 162 $html_form_content = $this->openOpenFormTag(). # <form 164 $this->getFormTagAttributesAsHTML(). # ....163 $this->getFormTagAttributesAsHTML(). # id/method/action/... 165 164 $this->closeOpenFormTag(). # > 166 165 $this->addHeading(). # heading -
trunk/core/viewhelper/form/formelement.core.php
r5544 r5922 70 70 * @var formelement_validation_errors 71 71 */ 72 protected $ formelement_validation_errors = array();72 protected $validation_errors = array(); 73 73 74 74 /** … … 202 202 203 203 /** 204 * Return the value (escaped)204 * Return the (escaped!) value of the formelement. 205 205 * 206 206 * @return string Escaped string … … 224 224 225 225 /** 226 * Returns the value (unescaped)226 * Returns the (unescaped!) value 227 227 * 228 228 * @return string Unescaped string … … 298 298 299 299 /** 300 * Returns boolean true if thisformelement 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. 302 302 * 303 303 * @return boolean True if formelement is required, false if not. … … 318 318 319 319 /** 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; 345 329 346 330 return $this; … … 482 466 483 467 /** 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 /** 484 490 * addValidator 485 491 * 486 492 * 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 490 495 * @return Clansuite_Formelement_Validator 491 496 */ 492 497 public function addValidator($validator) 493 498 { 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. 500 513 * 501 514 * @param Clansuite_Validator $validator Accepts a Clansuite_Validator Object that has to implement Clansuite_Validator_Interface. 502 515 * @return Clansuite_Formelement 503 516 */ 504 public function setValidator( Clansuite_Form_Validation_Interface$validator)517 public function setValidator(/*Clansuite_Formelement_Validates_Interface*/ $validator) 505 518 { 506 519 $this->validators[] = $validator; … … 510 523 511 524 /** 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. 514 526 * 515 527 * @see $validators array … … 529 541 else 530 542 { 531 # raise error flag532 $ formelement_validation_error = true;533 534 # fetch errorfrom the validator to the formelement543 # raise the error flag on the formelement 544 $this->setError(true); 545 546 # and transfer error message from the validator to the formelement 535 547 $this->addError($validator->getError()); 548 536 549 return false; 537 550 } … … 546 559 public function addError($validation_error) 547 560 { 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 } 550 583 551 584 /** … … 598 631 * @see $this->addDecorator() 599 632 * 600 * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM633 * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 601 634 * @return Clansuite_Formelement_Decorator 602 635 */ … … 612 645 * $form->addDecorator('fieldset')->setLegend('legendname'); 613 646 * 614 * WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM OBJECT647 * WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM OBJECT 615 648 * @return Clansuite_Formelement_Decorator 616 649 */ … … 639 672 $decoratorname = $decorator->name; 640 673 641 # WATCH IT! RECURSION!674 # WATCH OUT! RECURSION! 642 675 $this->addDecorator($decorator); 643 676 } … … 665 698 } 666 699 667 # WATCH IT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM700 # WATCH OUT! THIS BREAKS THE CHAINING IN REGARD TO THE FORM 668 701 # We dont return $this here, because $this would be the formelement. 669 702 # Insted the decorator is returned, to apply some properties. -
trunk/core/viewhelper/form/formelements/input.form.php
r5544 r5922 53 53 { 54 54 /** 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 58 59 */ 59 60 public $type; … … 108 109 */ 109 110 public $description; 110 111 111 112 /** 112 113 * A regular expression pattern, e.g. [A-Za-z]+\d+ … … 115 116 */ 116 117 public $pattern; 117 118 /** 118 119 /** 119 120 * String value for the placeholder attribute 120 121 * <input placeholder="some placeholder"> … … 132 133 { 133 134 $this->placeholder = $placeholder; 134 135 135 136 return $this; 136 137 } 137 138 139 /** 140 * Get Placeholder <input placeholder="some placeholder"> 141 * 142 * @return type 143 */ 138 144 public function getPlaceholder() 139 145 { … … 164 170 { 165 171 $this->additional_attr_text = $additional_attr_text; 172 166 173 return $this; 167 174 } 168 175 169 176 /** 170 * generates html code of element 177 * Renders the html code of the input element. 178 * 179 * @return string 171 180 */ 172 181 public function render() -
trunk/tests/unittests/core/viewhelper/form/form.core.php
r5875 r5922 156 156 public function testCopyObjectProperties() 157 157 { 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'); 173 175 } 174 176 … … 577 579 } 578 580 579 public function test Populate()581 public function testsetValues_DataArrayPassedToMethod() 580 582 { 581 583 # create multiselect "Snacks" with three options … … 587 589 $data = array('snacks' => array('cola', 'popcorn')); 588 590 589 $this->form-> populate($data);591 $this->form->setValues($data); 590 592 591 593 $snacks_array = $this->form->getElementByName('Snacks')->getValue(); … … 595 597 } 596 598 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' 602 612 ); 603 613 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); 619 615 } 620 616 … … 730 726 'This test has not been implemented yet.' 731 727 ); 732 } 728 }*/ 733 729 734 730 public function testValidateForm() 735 731 { 732 $this->form->addElement('textarea')->setRequired()->expect('required, string, maxlength=100'); 733 734 735 $this->form->validateForm(); 736 736 737 // Remove the following lines when you implement this test. 737 738 $this->markTestIncomplete( 738 739 'This test has not been implemented yet.' 739 740 ); 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 } 741 759 742 760 public function testsetErrorState() 743 761 { 744 762 $this->form->setErrorState(true); 763 $this->assertTrue($this->form->error); 745 764 $this->assertTrue($this->form->getErrorState()); 746 765 } … … 749 768 { 750 769 $this->form->setErrorState(true); 770 $this->assertTrue($this->form->error); 751 771 $this->assertTrue($this->form->getErrorState()); 752 772 753 773 $this->form->setErrorState(false); 774 $this->assertFalse($this->form->error); 754 775 $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());764 776 } 765 777
Note: See TracChangeset
for help on using the changeset viewer.
