diff --git a/src/Form.php b/src/Form.php index 2ad6856..d2dfc7f 100644 --- a/src/Form.php +++ b/src/Form.php @@ -130,6 +130,11 @@ public function __construct() $this->rules['in'] = function ($value, $param) { return in_array($value, $param); }; + + $this->rules['matchesvalueof'] = function ($value, $param) { + $this->message('matchesvalueof', "{field} must match the value of $param"); + return \Leaf\Http\Request::get($param) === $value; + }; } protected function test($rule, $valueToTest, $fieldName = 'item'): bool @@ -192,6 +197,10 @@ protected function test($rule, $valueToTest, $fieldName = 'item'): bool $param = ['Item']; } + if (!is_array($param)) { + $param = [$param]; + } + $this->addError($fieldName, sprintf( str_replace( ['{field}', '{Field}', '{value}'], @@ -313,10 +322,10 @@ public function addErrorMessage($field, ?string $message = null) } /** - * Add validation error message - * @param string|array $field The field to add the message to - * @param string|null $message The error message if $field is a string - */ + * Add validation error message + * @param string|array $field The field to add the message to + * @param string|null $message The error message if $field is a string + */ public function addMessage($field, ?string $message = null) { if (is_array($field)) {