83 lines
1.9 KiB
PHP
83 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Forms;
|
|
|
|
use RuntimeException;
|
|
use App\Forms\CommonForm;
|
|
|
|
class InquiryForm extends CommonForm
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function action_init_process(string $action, array &$formDatas = []): void
|
|
{
|
|
$fields = [
|
|
'title',
|
|
'email',
|
|
'content',
|
|
'status',
|
|
];
|
|
$filters = [
|
|
'status',
|
|
];
|
|
$indexFilter = $filters;
|
|
$batchjobFilters = ['status'];
|
|
switch ($action) {
|
|
case 'view':
|
|
$fields = [
|
|
'title',
|
|
'email',
|
|
'status',
|
|
'created_at',
|
|
'content'
|
|
];
|
|
break;
|
|
case 'index':
|
|
$fields = [
|
|
'title',
|
|
'email',
|
|
'status',
|
|
'created_at'
|
|
];
|
|
break;
|
|
case 'download':
|
|
$fields = [
|
|
'title',
|
|
'email',
|
|
'status',
|
|
'created_at',
|
|
'content'
|
|
];
|
|
break;
|
|
}
|
|
$this->setFormFields($fields);
|
|
$this->setFormRules($action, $fields);
|
|
$this->setFormFilters($filters);
|
|
$this->setFormOptions($action, $filters, $formDatas);
|
|
$this->setIndexFilters($indexFilter);
|
|
$this->setBatchjobFilters($batchjobFilters);
|
|
}
|
|
|
|
public function getFormRule(string $action, string $field, array $formRules): array
|
|
{
|
|
switch ($field) {
|
|
case "title":
|
|
case "content":
|
|
$formRules[$field] = "required|trim|string";
|
|
break;
|
|
case "email":
|
|
$formRules[$field] = sprintf("required|trim|valid_email%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
|
break;
|
|
case "status":
|
|
$formRules[$field] = "permit_empty|trim|string";
|
|
break;
|
|
default:
|
|
$formRules = parent::getFormRule($action, $field, $formRules);
|
|
break;
|
|
}
|
|
return $formRules;
|
|
}
|
|
}
|