refactor(web/add_contest): uoj_form_v2

This commit is contained in:
Baoshuo Ren 2022-12-24 11:11:06 +08:00
parent 354dd361b0
commit f945a6cfdb
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -5,13 +5,13 @@ requirePHPLib('form');
Auth::check() || redirectToLogin();
UOJContest::userCanCreateContest(Auth::user()) || UOJResponse::page403();
$time_form = new UOJBs4Form('time');
$time_form->addVInput(
$time_form = new UOJForm('time');
$time_form->addInput(
'name',
'text',
'比赛标题',
'New Contest',
function ($name, &$vdata) {
[
'label' => '比赛标题',
'default_value' => 'New Contest',
'validator_php' => function ($name, &$vdata) {
if ($name == '') {
return '标题不能为空';
}
@ -30,29 +30,32 @@ $time_form->addVInput(
return '';
},
null
]
);
$time_form->addVInput(
$time_form->addInput(
'start_time',
'text',
'开始时间',
date("Y-m-d H:i:s"),
function ($str, &$vdata) {
[
'div_class' => 'mt-2',
'label' => '开始时间',
'default_value' => date("Y-m-d H:i:s"),
'validator_php' => function ($str, &$vdata) {
try {
$vdata['start_time'] = new DateTime($str);
} catch (Exception $e) {
return '无效时间格式';
}
return '';
},
null
]
);
$time_form->addVInput(
$time_form->addInput(
'last_min',
'text',
'时长(单位:分钟)',
180,
function ($str, &$vdata) {
[
'div_class' => 'mt-2',
'label' => '时长(单位:分钟)',
'default_value' => '180',
'validator_php' => function ($str, &$vdata) {
if (!validateUInt($str)) {
return '必须为一个整数';
}
@ -61,7 +64,7 @@ $time_form->addVInput(
return '';
},
null
]
);
$time_form->handle = function (&$vdata) {
$start_time_str = $vdata['start_time']->format('Y-m-d H:i:s');
@ -75,6 +78,7 @@ $time_form->handle = function (&$vdata) {
$time_form->succ_href = "/contests";
$time_form->runAtServer();
?>
<?php echoUOJPageHeader('添加比赛') ?>
<div class="row">
@ -82,7 +86,6 @@ $time_form->runAtServer();
<div class="col-lg-9">
<div class="card card-default mb-2">
<div class="card-body">
<h1 class="card-title">添加比赛</h1>
<div class="w-full" style="max-width: 400px">