From f945a6cfdb0ed5b9676c4c8f28a52467c77a9c92 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 24 Dec 2022 11:11:06 +0800 Subject: [PATCH] refactor(web/add_contest): uoj_form_v2 --- web/app/controllers/add_contest.php | 95 +++++++++++++++-------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/web/app/controllers/add_contest.php b/web/app/controllers/add_contest.php index 72b7776..ae5b6a7 100644 --- a/web/app/controllers/add_contest.php +++ b/web/app/controllers/add_contest.php @@ -5,63 +5,66 @@ 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) { - if ($name == '') { - return '标题不能为空'; - } + [ + 'label' => '比赛标题', + 'default_value' => 'New Contest', + 'validator_php' => function ($name, &$vdata) { + if ($name == '') { + return '标题不能为空'; + } - if (strlen($name) > 100) { - return '标题过长'; - } + if (strlen($name) > 100) { + return '标题过长'; + } - $name = HTML::escape($name); + $name = HTML::escape($name); - if ($name === '') { - return '无效编码'; - } + if ($name === '') { + return '无效编码'; + } - $vdata['name'] = $name; + $vdata['name'] = $name; - return ''; - }, - null + return ''; + }, + ] ); -$time_form->addVInput( +$time_form->addInput( 'start_time', - 'text', - '开始时间', - date("Y-m-d H:i:s"), - function ($str, &$vdata) { - try { - $vdata['start_time'] = new DateTime($str); - } catch (Exception $e) { - return '无效时间格式'; - } - return ''; - }, - null + [ + '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 ''; + }, + ] ); -$time_form->addVInput( +$time_form->addInput( 'last_min', - 'text', - '时长(单位:分钟)', - 180, - function ($str, &$vdata) { - if (!validateUInt($str)) { - return '必须为一个整数'; - } + [ + 'div_class' => 'mt-2', + 'label' => '时长(单位:分钟)', + 'default_value' => '180', + 'validator_php' => function ($str, &$vdata) { + if (!validateUInt($str)) { + return '必须为一个整数'; + } - $vdata['last_min'] = $str; + $vdata['last_min'] = $str; - return ''; - }, - null + return ''; + }, + ] ); $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(); ?> +
@@ -82,7 +86,6 @@ $time_form->runAtServer();
-

添加比赛