Skip to content

Commit

Permalink
update forms.md (#199)
Browse files Browse the repository at this point in the history
Co-authored-by: hacan359 <[email protected]>
  • Loading branch information
hacan359 and hacan359 authored Jan 15, 2024
1 parent e501e5f commit 69e0f6a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions guide/en/start/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EchoForm extends FormModel
return $this->message;
}

public function getAttributeLabels(): array
public function getPropertyLabels(): array
{
return [
'message' => 'Message',
Expand Down Expand Up @@ -67,6 +67,7 @@ use App\Form\EchoForm;
use Yiisoft\Yii\View\ViewRenderer;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Hydrator\Hydrator;
use Yiisoft\Http\Method;

class EchoController
Expand All @@ -81,9 +82,10 @@ class EchoController
public function say(ServerRequestInterface $request): ResponseInterface
{
$form = new EchoForm();
$hydrator = new Hydrator();

if ($request->getMethod() === Method::POST) {
$form->load($request->getParsedBody());
$hydrator->hydrate($form, $request->getParsedBody()[$form->getFormName()]);
}

return $this->viewRenderer->render('say', [
Expand Down Expand Up @@ -209,6 +211,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Http\Method;
use Yiisoft\Validator\Validator;
use Yiisoft\Yii\View\ViewRenderer;
use Yiisoft\Hydrator\Hydrator;

class EchoController
{
Expand All @@ -222,9 +225,10 @@ class EchoController
public function say(ServerRequestInterface $request, Validator $validator): ResponseInterface
{
$form = new EchoForm();
$hydrator = new Hydrator();

if ($request->getMethod() === Method::POST) {
$form->load($request->getParsedBody());
$hydrator->hydrate($form, $request->getParsedBody()[$form->getFormName()]);
$validator->validate($form);
}

Expand Down Expand Up @@ -255,7 +259,7 @@ class EchoForm extends FormModel implements RulesProviderInterface
return $this->message;
}

public function getAttributeLabels(): array
public function getPropertyLabels(): array
{
return [
'message' => 'Message',
Expand Down

0 comments on commit 69e0f6a

Please sign in to comment.