Bicycle/App/Controller/FeedbackController.php
Egor Isaev b3c8188ee3 dev
2026-06-23 16:30:58 +03:00

53 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description FeedbackController.php
* @copyright (c) 23/06/2026
*/
namespace App\Controller;
use System\Classes\Controller;
use System\Classes\Request;
use System\Classes\Validation;
use System\Classes\HTTP\Request as HTTPRequest;
/**
* Демонстрация формы с валидацией.
* CSRF проверяется автоматически в Controller::before().
* Один экшен и показывает форму (GET), и обрабатывает её (POST).
*/
class FeedbackController extends Controller
{
/**
* @return string
* @throws \System\Classes\MyException
*/
public function indexAction(): string
{
$request = Request::$current;
$errors = [];
if ($request->method() === HTTPRequest::POST) {
// CSRF уже проверен в BaseController::before(). Здесь — только данные.
$validation = Validation::factory($request->post())
->label('email', 'E-mail')
->label('message', 'Сообщение')
->rule('email', 'required')
->rule('email', 'email')
->rule('message', 'required')
->rule('message', 'min_length', [10]);
if ($validation->check()) {
// Данные чистые — здесь было бы сохранение/отправка письма.
return $this->render('feedback_ok', ['email' => $request->post('email')]);
}
$errors = $validation->errors();
}
return $this->render('feedback', ['errors' => $errors]);
}
}