45 lines
1.2 KiB
PHP
45 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 getFormFields(string $action, ?array $fields = null): array
|
|
{
|
|
return $fields ?? ["id", "passwd"];
|
|
}
|
|
public function getFormFilters(string $action, ?array $fields = null): array
|
|
{
|
|
return $fields ?? [];
|
|
}
|
|
public function getBatchjobButtons(string $action = 'index', ?array $buttions = null): array
|
|
{
|
|
return $buttions ?? [];
|
|
}
|
|
public function getFormRule(string $action, string $field, array $rules = []): array
|
|
{
|
|
$rules = parent::getFormRule($action, $field, $rules);
|
|
switch ($field) {
|
|
case "id":
|
|
$rule = "required|trim|min_length[4]|max_length[20]";
|
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
|
$rules[$field] = $rule;
|
|
break;
|
|
case "passwd":
|
|
$rules[$field] = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
|
break;
|
|
default:
|
|
$rules = parent::getFormRule($action, $field, $rules);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
}
|