[
'class' => '',
],
'submit_button' => [
'class' => 'btn btn-secondary',
],
];
public $submit_button_config = [];
public $control_label_config = ['class' => 'col-sm-2'];
public $input_config = ['class' => 'col-sm-3'];
public $textarea_config = ['class' => 'col-sm-10'];
public function __construct($form_name) {
$this->form_name = $form_name;
$this->succ_href = UOJContext::requestURI();
$this->handle = function (&$vdata) {
};
$this->run_at_server_handler["check-{$this->form_name}"] = function () {
die(json_encode($this->validateAtServer()));
};
$this->run_at_server_handler["submit-{$this->form_name}"] = function () {
if ($this->no_submit) {
UOJResponse::page404();
}
foreach ($this->data as $field) {
if (!isset($field['no_val']) && !isset($_POST[$field['name']])) {
UOJResponse::message('The form is incomplete.');
}
}
if (UOJContext::requestMethod() == 'POST') {
$len = UOJContext::contentLength();
if ($len === null) {
UOJResponse::page403();
} elseif ($len > $this->max_post_size) {
UOJResponse::message('The form is too large.');
}
}
crsf_defend();
$errors = $this->validateAtServer();
if ($errors) {
$err_str = '';
foreach ($errors as $name => $err) {
$esc_err = htmlspecialchars($err);
$err_str .= "$name: $esc_err
";
}
UOJResponse::message($err_str);
}
$fun = $this->handle;
$fun($this->vdata);
if ($this->succ_href !== 'none') {
redirectTo($this->succ_href);
}
die();
};
}
public function setAjaxSubmit($js) {
$GLOBALS['REQUIRE_LIB']['jquery.form'] = '';
$this->ajax_submit_js = $js;
}
public function add($name, $html, $validator_php, $validator_js) {
$this->main_html .= $html;
$this->data[] = array(
'name' => $name,
'validator_php' => $validator_php,
'validator_js' => $validator_js
);
}
public function appendHTML($html) {
$this->main_html .= $html;
}
public function addNoVal($name, $html) {
$this->main_html .= $html;
$this->data[] = array(
'name' => $name,
'validator_js' => 'always_ok',
'no_val' => ''
);
}
public function addHidden($name, $default_value, $validator_php, $validator_js) {
$default_value = HTML::escape($default_value);
$html = <<