diff --git a/form/FormViewHelper.php b/form/FormViewHelper.php index 48aa07d..a1186f8 100644 --- a/form/FormViewHelper.php +++ b/form/FormViewHelper.php @@ -26,12 +26,12 @@ class FormViewHelper extends ViewHelper return $this; } - public function value($field) + public function value($field, $default = '') { if (isset($this->data['values'][$field])) { return $this->view->escape($this->data['values'][$field]); } - return ''; + return $this->view->escape($default); } public function message($field) diff --git a/validator/EqualValidator.php b/validator/EqualValidator.php new file mode 100644 index 0000000..d8e0120 --- /dev/null +++ b/validator/EqualValidator.php @@ -0,0 +1,39 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage validator + * @since 2010-04-26 + * @version SVN: $Id$ + * @filesource $URL$ + */ + +class EqualValidator extends Validator +{ + + const NOT_EQUAL = 'not_match'; + + protected $templates = array(self::NOT_EQUAL => 'Tokens do not match'); + + protected $token; + + public function __construct($token) + { + $this->token = $token; + } + + public function isValid($value, $context = null) + { + $this->setValue($value); + if ($this->token === null) { + throw new Exception('Token not defined.'); + } + + if ($value !== $this->token) { + $this->error(); + return false; + } + return true; + } +} \ No newline at end of file diff --git a/validator/Validator.php b/validator/Validator.php index d201b3d..765a7f3 100644 --- a/validator/Validator.php +++ b/validator/Validator.php @@ -29,8 +29,11 @@ abstract class Validator implements iValidator $this->message = null; } - public function setMessage($key, $message) + public function setMessage($message, $key = null) { + if ($key === null) { + $key = current(array_keys($this->templates)); + } $this->templates[$key] = $message; }