mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 12:18:42 +00:00
feat(web): UOJForm::addInput()
This commit is contained in:
parent
d72f178251
commit
0f4977727a
@ -120,6 +120,53 @@ class UOJForm {
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
|
||||
public function addInput($name, $config) {
|
||||
$config += [
|
||||
'type' => 'text',
|
||||
'div_class' => '',
|
||||
'input_class' => 'form-control',
|
||||
'default_value' => '',
|
||||
'label' => '',
|
||||
'label_class' => 'form-label',
|
||||
'placeholder' => '',
|
||||
'help' => '',
|
||||
'help_class' => '',
|
||||
'validator_php' => function ($x) {
|
||||
return '';
|
||||
},
|
||||
'validator_js' => null,
|
||||
];
|
||||
|
||||
$html = '';
|
||||
$html .= HTML::tag_begin('div', ['class' => $config['div_class'], 'id' => "div-$name"]);
|
||||
|
||||
if ($config['label']) {
|
||||
$html .= HTML::tag('label', [
|
||||
'class' => $config['label_class'],
|
||||
'for' => "input-$name",
|
||||
'id' => "label-$name"
|
||||
], $config['label']);
|
||||
}
|
||||
|
||||
$html .= HTML::empty_tag('input', [
|
||||
'class' => $config['input_class'],
|
||||
'type' => $config['type'],
|
||||
'name' => $name,
|
||||
'id' => "input-$name",
|
||||
'value' => $config['default_value'],
|
||||
'placeholder' => $config['placeholder'],
|
||||
]);
|
||||
$html .= HTML::tag('div', ['class' => 'invalid-feedback', 'id' => "help-$name"], '');
|
||||
|
||||
if ($config['help']) {
|
||||
$html .= HTML::tag('div', ['class' => $config['help_class']], $config['help']);
|
||||
}
|
||||
|
||||
$html .= HTML::tag_end('div');
|
||||
|
||||
$this->add($name, $html, $config['validator_php'], $config['validator_js']);
|
||||
}
|
||||
|
||||
public function addCheckbox($name, $config) {
|
||||
$config += [
|
||||
'checked' => false,
|
||||
@ -346,7 +393,7 @@ class UOJForm {
|
||||
}
|
||||
|
||||
if ($this->config['confirm']['smart']) {
|
||||
$this->config['confirm']['text'] = '你真的要' . $this->config['submit']['text'] . '吗?';
|
||||
$this->config['confirm']['text'] = '你真的要' . $this->config['submit_button']['text'] . '吗?';
|
||||
}
|
||||
if ($this->config['confirm']['text']) {
|
||||
echo <<<EOD
|
||||
|
Loading…
Reference in New Issue
Block a user