public function __construct() {
}
+ /**
+ * Returns the current prefix of the form
+ * The RequestHandler is asked
+ *
+ * @return String
+ */
+ protected function getPrefix() {
+ return t3lib_div::makeInstance('tx_form_System_Request')->getPrefix();
+ }
+
/**
* Create a rule object according to class
* and sent some arguments
* @return tx_form_Validate
*/
public function addRule($rule, $fieldName, $breakOnError = FALSE) {
- $this->rules[] = array(
+ $prefix = $this->getPrefix();
+ $this->rules[$prefix][] = array(
'instance' => (object) $rule,
'fieldName' => (string) $fieldName,
'breakOnError' => (boolean) $breakOnError
);
if ($rule->messageMustBeDisplayed()) {
- if (!isset($this->messages[$fieldName])) {
- $this->messages[$fieldName] = array();
+ if (!isset($this->messages[$prefix][$fieldName])) {
+ $this->messages[$prefix][$fieldName] = array();
}
- end($this->rules);
- $key = key($this->rules);
+ end($this->rules[$prefix]);
+ $key = key($this->rules[$prefix]);
$message = $rule->getMessage();
- $this->messages[$fieldName][$key][$key + 1] = $message['cObj'];
- $this->messages[$fieldName][$key][($key + 1) . '.'] = $message['cObj.'];
+ $this->messages[$prefix][$fieldName][$key][$key + 1] = $message['cObj'];
+ $this->messages[$prefix][$fieldName][$key][($key + 1) . '.'] = $message['cObj.'];
}
return $this;
}
+
/**
* Returns TRUE when each rule in the chain returns valid
* When a rule has breakOnError set and the rule does not validate,
* @return boolean True if all rules validate
*/
public function isValid() {
- $this->errors = array();
+ $prefix = $this->getPrefix();
+ $this->errors[$prefix] = array();
$result = TRUE;
- foreach ($this->rules as $key => $element) {
+ foreach ($this->rules[$prefix] as $key => $element) {
$rule = $element['instance'];
$fieldName = $element['fieldName'];
continue;
}
$result = FALSE;
- if (!isset($this->errors[$fieldName])) {
- $this->errors[$fieldName] = array();
+ if (!isset($this->errors[$prefix][$fieldName])) {
+ $this->errors[$prefix][$fieldName] = array();
}
$error = $rule->getError();
- $this->errors[$fieldName][$key][$key + 1] = $error['cObj'];
- $this->errors[$fieldName][$key][($key + 1) . '.'] = $error['cObj.'];
+ $this->errors[$prefix][$fieldName][$key][$key + 1] = $error['cObj'];
+ $this->errors[$prefix][$fieldName][$key][($key + 1) . '.'] = $error['cObj.'];
if ($element['breakOnError']) {
break;
}
* @return array
*/
public function getMessages() {
- return $this->messages;
+ return $this->messages[$this->getPrefix()];
}
/**
* @return array
*/
public function getMessagesByName($name) {
- return $this->messages[$name];
+ return $this->messages[$this->getPrefix()][$name];
}
/**
* @return boolean
*/
public function hasMessage($name) {
- if (isset($this->messages[$name])) {
+ if (isset($this->messages[$this->getPrefix()][$name])) {
return TRUE;
}
return FALSE;
* @return array
*/
public function getErrors() {
- return $this->errors;
+ return $this->errors[$this->getPrefix()];
}
/**
* @return array
*/
public function getErrorsByName($name) {
- return $this->errors[$name];
+ return $this->errors[$this->getPrefix()][$name];
}
/**
* @return boolean
*/
public function hasErrors($name) {
- if (isset($this->errors[$name])) {
+ if (isset($this->errors[$this->getPrefix()][$name])) {
return TRUE;
}
return FALSE;