Вот мой контроллер для выполнения формы
Код: Выделить всё
if (!$this->validate([
'name' => [
'rules' => 'required|min_length[3]|max_length[25]',
'errors' => [
'required' => 'Name actress must be filled.',
'min_length' => 'Name actress minimum 3 character.',
'max_length' => 'Name actress maximum 25 character.',
]
],
'years' => [
'rules' => 'required|min_length[4]|max_length[4]|is_natural',
'errors' => [
'required' => 'Years must be filled.',
'min_length' => 'Years minimum 4 numbers.',
'max_length' => 'Years maximum 4 numbers.',
'is_natural' => 'Years only numbers.',
]
],
])) {
$validation = $this->validation;
session()->setFlashdata('wrong', 'there is an error, check your form again.');
return redirect()->to('/home/actress')->withInput()->with('validation', $validation);
Код: Выделить всё
public function actress(): string
{
$data = [
'nationalities' => $this->NationalityModel->findAll(),
'validation' => $this->validation
];
return view('index/actress', $data);
}
Код: Выделить всё
Name
Подробнее здесь: [url]https://stackoverflow.com/questions/78434846/codeigniter-4-validation-rules-not-working[/url]
Мобильная версия