From 22216bff3f461067c44cf24abd6d0429d5ca4792 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 12:22:13 +0000
Subject: [PATCH 01/13] Initial plan
From 39a7d1f6dfe1635fb8bb66da252292113b3c22a8 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 12:33:01 +0000
Subject: [PATCH 02/13] docs: add callback rule example for custom form
validation
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/bb024534-e526-4189-b401-4dca5f506d38
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index cd4156c2..fd3e3f86 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -49,6 +49,43 @@ final class Form extends FormModel
In the above example, the `Form` has a single string property `$message` which length should be at least
of two characters. There's also a custom label for the property.
+## Custom validation with callback rule
+
+If built-in rules are not enough, use the `Callback` rule as a PHP attribute and put custom logic into a method.
+For example, you can validate that a field contains a UUID v7:
+
+```php
+addError('Message must be a valid UUID v7.');
+ }
+}
+```
+
+You can combine `Callback` with other attributes such as `Required`, `Length`, or `Regex` on the same property.
+In this example, `Uuid::isValid()` represents your project's UUID helper.
+See [Callback rule details](https://github.com/yiisoft/validator/blob/master/docs/guide/en/built-in-rules-callback.md)
+for full examples and available method signatures.
+
## Using the form
Now that you have a form, use it in your action from "[Saying Hello](hello.md)".
From 86ba4ba995519b0cd214d8084dec1e6bb4a37298 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 12:34:55 +0000
Subject: [PATCH 03/13] docs: refine callback example imports and method naming
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/bb024534-e526-4189-b401-4dca5f506d38
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index fd3e3f86..2ee1d181 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -61,16 +61,17 @@ declare(strict_types=1);
namespace App\Web\Echo;
+use App\Uuid;
use Yiisoft\FormModel\FormModel;
use Yiisoft\Validator\Result;
use Yiisoft\Validator\Rule\Callback;
final class Form extends FormModel
{
- #[Callback(method: 'validateMessageAsUuidV7')]
+ #[Callback(method: 'validateUuidV7')]
public string $message = '';
- private function validateMessageAsUuidV7(mixed $value): Result
+ private function validateUuidV7(mixed $value): Result
{
if (Uuid::isValid($value, 'v7')) {
return new Result();
From 4d25283b7c22719f541b906382911ea178f52bcd Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 14:16:54 +0000
Subject: [PATCH 04/13] docs: merge callback guidance with main form example
using YAML
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/a7576578-7d52-4689-96cb-73c66933180d
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 2ee1d181..13985f6f 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -52,7 +52,7 @@ of two characters. There's also a custom label for the property.
## Custom validation with callback rule
If built-in rules are not enough, use the `Callback` rule as a PHP attribute and put custom logic into a method.
-For example, you can validate that a field contains a UUID v7:
+You can add it to the same form model. For example, add a `yaml` field and validate that it contains valid YAML:
```php
addError('The value must be a string.');
+ }
+
+ $notYamlMessage = 'This value is not a valid YAML.';
+
+ try {
+ $data = yaml_parse($value);
+ } catch (Exception) {
+ return (new Result())->addError($notYamlMessage);
+ }
+
+ if ($data === false) {
+ return (new Result())->addError($notYamlMessage);
}
- return (new Result())->addError('Message must be a valid UUID v7.');
+ return new Result();
}
}
```
You can combine `Callback` with other attributes such as `Required`, `Length`, or `Regex` on the same property.
-In this example, `Uuid::isValid()` represents your project's UUID helper.
See [Callback rule details](https://github.com/yiisoft/validator/blob/master/docs/guide/en/built-in-rules-callback.md)
for full examples and available method signatures.
From c38e01bf842819e2a26aea00fc9eb4974e8784ad Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 14:19:13 +0000
Subject: [PATCH 05/13] docs: polish callback yaml example wording
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/a7576578-7d52-4689-96cb-73c66933180d
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 13985f6f..1fb8b07d 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -52,7 +52,7 @@ of two characters. There's also a custom label for the property.
## Custom validation with callback rule
If built-in rules are not enough, use the `Callback` rule as a PHP attribute and put custom logic into a method.
-You can add it to the same form model. For example, add a `yaml` field and validate that it contains valid YAML:
+You can add it to your form model. For example, add a `yaml` field and validate that it contains valid YAML:
```php
addError('The value must be a string.');
}
- $notYamlMessage = 'This value is not a valid YAML.';
+ $notYamlMessage = 'This value is not valid YAML.';
try {
$data = yaml_parse($value);
From 2eaf0d372c60876a5a3c51a9c815f7cd5210f6cf Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 14:36:35 +0000
Subject: [PATCH 06/13] docs: move callback yaml example into creating-form
section
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/7e4e20c0-6bab-48c2-b4d2-345a41e0479b
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 1fb8b07d..33464a04 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -34,33 +34,6 @@ declare(strict_types=1);
namespace App\Web\Echo;
-use Yiisoft\FormModel\FormModel;
-use Yiisoft\Validator\Label;
-use Yiisoft\Validator\Rule\Length;
-
-final class Form extends FormModel
-{
- #[Label('The message to be echoed')]
- #[Length(min: 2)]
- public string $message = '';
-}
-```
-
-In the above example, the `Form` has a single string property `$message` which length should be at least
-of two characters. There's also a custom label for the property.
-
-## Custom validation with callback rule
-
-If built-in rules are not enough, use the `Callback` rule as a PHP attribute and put custom logic into a method.
-You can add it to your form model. For example, add a `yaml` field and validate that it contains valid YAML:
-
-```php
-
Date: Fri, 15 May 2026 14:38:52 +0000
Subject: [PATCH 07/13] docs: clarify creating-form text for callback example
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/7e4e20c0-6bab-48c2-b4d2-345a41e0479b
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 33464a04..19ff475c 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -25,7 +25,8 @@ make composer require yiisoft/form-model
## Creating a form
The data to be requested from the user will be represented by a `Form` class as shown below and
-saved in the file `/src/Web/Echo/Form.php`:
+saved in the file `/src/Web/Echo/Form.php`. The example uses both built-in validation and custom
+validation with the `Callback` rule:
```php
Date: Fri, 15 May 2026 15:06:31 +0000
Subject: [PATCH 08/13] docs: update forms guide examples to include yaml field
usage
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 19ff475c..f90a2c9b 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -1,6 +1,6 @@
# Working with forms
-This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message via form.
+This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and YAML via form.
Through this tutorial, you will learn how to:
@@ -173,11 +173,13 @@ $htmlForm = Html::form()
= $htmlForm->open() ?>
= Field::text($form, 'message')->required() ?>
+ = Field::text($form, 'yaml')->required() ?>
= Html::submitButton('Say') ?>
= $htmlForm->close() ?>
isValid()): ?>
Echo said: = Html::encode($form->message) ?>
+ YAML: = Html::encode($form->yaml) ?>
```
@@ -199,11 +201,11 @@ The template renders the CSRF token value as a hidden input to ensure that the r
the form page and not from another website. It will be submitted along with POST form data. Omitting it would result in
[HTTP response code 422](https://tools.ietf.org/html/rfc4918#section-11.2).
-You use `Field::text()` to output "message" field, so it takes care about filling the value, escaping it,
+You use `Field::text()` to output "message" and "yaml" fields, so it takes care about filling the value, escaping it,
rendering field label and validation errors.
Now, in case you submit an empty message, you will get a validation error: "The message to be echoed must contain
-at least 2 characters."
+at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error.
## Trying it Out
@@ -213,9 +215,9 @@ To see how it works, use your browser to access the following URL:
http://localhost:8080/say
```
-You will see a page with a form input field and a label that indicates what data to enter.
+You will see a page with two form input fields and labels that indicate what data to enter.
Also, the form has a "submit" button labeled "Say". If you click the "submit" button without entering anything, you will see
-that the field is required. If you enter a single character, the form displays an error message next to
+that fields are required. If you enter a single character in message or invalid YAML, the form displays an error message next to
the problematic input field.

From ad495d0fcd11e3bd1a75810d386e5c75aa791657 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 15:08:47 +0000
Subject: [PATCH 09/13] docs: clarify yaml validation purpose in forms tutorial
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index f90a2c9b..7043295c 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -1,6 +1,6 @@
# Working with forms
-This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and YAML via form.
+This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and a YAML value via form to demonstrate both built-in and custom validation.
Through this tutorial, you will learn how to:
@@ -205,7 +205,7 @@ You use `Field::text()` to output "message" and "yaml" fields, so it takes care
rendering field label and validation errors.
Now, in case you submit an empty message, you will get a validation error: "The message to be echoed must contain
-at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error.
+at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error from `validateYaml()`.
## Trying it Out
From 4a39e1a0f7729cd2bc5803a821603b7ccc19c0d2 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 15:10:39 +0000
Subject: [PATCH 10/13] docs: improve callback validation wording in forms
guide
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 7043295c..9eaf9c8c 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -1,6 +1,6 @@
# Working with forms
-This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and a YAML value via form to demonstrate both built-in and custom validation.
+This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and a YAML value via form to demonstrate both built-in and callback-based custom validation in one example.
Through this tutorial, you will learn how to:
@@ -205,7 +205,7 @@ You use `Field::text()` to output "message" and "yaml" fields, so it takes care
rendering field label and validation errors.
Now, in case you submit an empty message, you will get a validation error: "The message to be echoed must contain
-at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error from `validateYaml()`.
+at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error from the callback rule in the form class.
## Trying it Out
From 106255ae4224ecb1fc1e4a2531ca82e77076cd95 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 15:12:29 +0000
Subject: [PATCH 11/13] docs: simplify intro and yaml error wording
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 9eaf9c8c..d2384b69 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -1,6 +1,6 @@
# Working with forms
-This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and a YAML value via form to demonstrate both built-in and callback-based custom validation in one example.
+This section continues to improve on "Saying Hello." Instead of using URL, you will now ask a user for a message and a YAML value via form.
Through this tutorial, you will learn how to:
@@ -205,7 +205,7 @@ You use `Field::text()` to output "message" and "yaml" fields, so it takes care
rendering field label and validation errors.
Now, in case you submit an empty message, you will get a validation error: "The message to be echoed must contain
-at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error from the callback rule in the form class.
+at least 2 characters." If `yaml` value is not valid YAML, you will also get a validation error.
## Trying it Out
From d98eadcec0b375275092580cb41ee15ce5350024 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 19:11:54 +0000
Subject: [PATCH 12/13] docs: use textarea for yaml field in forms example
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/1e2cda1d-9b78-4fa3-a78d-75ec80b31b40
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index d2384b69..840875fd 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -173,7 +173,7 @@ $htmlForm = Html::form()
= $htmlForm->open() ?>
= Field::text($form, 'message')->required() ?>
- = Field::text($form, 'yaml')->required() ?>
+ = Field::textarea($form, 'yaml')->required() ?>
= Html::submitButton('Say') ?>
= $htmlForm->close() ?>
@@ -201,7 +201,7 @@ The template renders the CSRF token value as a hidden input to ensure that the r
the form page and not from another website. It will be submitted along with POST form data. Omitting it would result in
[HTTP response code 422](https://tools.ietf.org/html/rfc4918#section-11.2).
-You use `Field::text()` to output "message" and "yaml" fields, so it takes care about filling the value, escaping it,
+You use `Field::text()` and `Field::textarea()` to output "message" and "yaml" fields, so it takes care about filling the value, escaping it,
rendering field label and validation errors.
Now, in case you submit an empty message, you will get a validation error: "The message to be echoed must contain
@@ -215,7 +215,7 @@ To see how it works, use your browser to access the following URL:
http://localhost:8080/say
```
-You will see a page with two form input fields and labels that indicate what data to enter.
+You will see a page with a text field and a textarea with labels that indicate what data to enter.
Also, the form has a "submit" button labeled "Say". If you click the "submit" button without entering anything, you will see
that fields are required. If you enter a single character in message or invalid YAML, the form displays an error message next to
the problematic input field.
From d767effe387c2ed324cd425b55533eb20d6cb19a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Fri, 15 May 2026 19:16:10 +0000
Subject: [PATCH 13/13] docs: add label attribute for yaml field in form model
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/d70634bb-2962-4194-b976-6de0578f8669
Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
---
src/guide/start/forms.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/guide/start/forms.md b/src/guide/start/forms.md
index 840875fd..bef12a0d 100644
--- a/src/guide/start/forms.md
+++ b/src/guide/start/forms.md
@@ -48,6 +48,7 @@ final class Form extends FormModel
#[Length(min: 2)]
public string $message = '';
+ #[Label('YAML content')]
#[Callback(method: 'validateYaml')]
public string $yaml = '';