44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Forms\Auth;
|
|
|
|
use App\Forms\CommonForm;
|
|
|
|
class LocalForm extends CommonForm
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function action_init_process(string $action, array &$formDatas = []): void
|
|
{
|
|
$fields = ['id', 'passwd'];
|
|
$filters = [];
|
|
switch ($action) {
|
|
case 'login':
|
|
case 'login_form':
|
|
break;
|
|
}
|
|
$this->setFormFields($fields);
|
|
$this->setFormRules($fields);
|
|
$this->setFormFilters($filters);
|
|
$this->setFormOptions($filters);
|
|
$this->setBatchjobFilters($filters);
|
|
}
|
|
public function getFormRule(string $field, array $formRules): array
|
|
{
|
|
switch ($field) {
|
|
case "id":
|
|
$formRules[$field] = sprintf("required|trim|min_length[4]|max_length[20]%s", in_array($this->_action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
|
break;
|
|
case "passwd":
|
|
$formRules[$field] = in_array($this->_action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
|
break;
|
|
default:
|
|
$formRules = parent::getFormRule($field, $formRules);
|
|
break;
|
|
}
|
|
return $formRules;
|
|
}
|
|
}
|