|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
class Form {
|
|
|
|
|
|
- const BOOLEAN_OPTIONS = [
|
|
|
+ public const BOOLEAN_OPTIONS = [
|
|
|
0 => NO,
|
|
|
1 => YES,
|
|
|
];
|
|
|
@@ -20,7 +20,7 @@ class Form {
|
|
|
* @return bool
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public static function checkRecaptcha(float $required_score = 0.5) {
|
|
|
+ public static function checkRecaptcha(float $required_score = 0.5): bool {
|
|
|
|
|
|
if(!defined("GOOGLE_RECAPTCHA_SECRET")) return true;
|
|
|
|
|
|
@@ -37,40 +37,26 @@ class Form {
|
|
|
if(isset($response->score)) {
|
|
|
return $response->score >= $required_score;
|
|
|
}
|
|
|
- else {
|
|
|
- return $response->success;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function renderYearOptions($min = null, $max = null, $selected_value = null) {
|
|
|
-
|
|
|
- if(empty($min)) $min = date("Y") - 100;
|
|
|
- if(empty($max)) $max = date("Y") - 16;
|
|
|
|
|
|
- for($i = $min; $i <= $max; $i++) {
|
|
|
- $selected = ($selected_value == $i) ? "selected" : "";
|
|
|
- ?>
|
|
|
- <option value="<?=$i?>" <?=$selected?>><?=$i?></option>
|
|
|
- <?php
|
|
|
- }
|
|
|
+ return $response->success;
|
|
|
}
|
|
|
|
|
|
- public static function renderYearOptionsDescending($min = null, $max = null, $selected_value = null) {
|
|
|
+ public static function renderYearOptions(?int $min = null, ?int $max = null, ?int $selected_value = null): void {
|
|
|
|
|
|
- if(empty($min)) $min = date("Y") - 100;
|
|
|
- if(empty($max)) $max = date("Y") - 16;
|
|
|
+ if($min === null) $min = date("Y") - 100;
|
|
|
+ if($max === null) $max = date("Y") - 16;
|
|
|
|
|
|
- for($i = $max; $i >= $min; $i--) {
|
|
|
- $selected = ($selected_value == $i) ? "selected" : "";
|
|
|
+ for($i = $min; $i <= $max; $i++) {
|
|
|
+ $selected = ((int) $selected_value === $i) ? "selected" : "";
|
|
|
?>
|
|
|
<option value="<?=$i?>" <?=$selected?>><?=$i?></option>
|
|
|
<?php
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function renderMonthOptions($selected_value = null) {
|
|
|
+ public static function renderMonthOptions($selected_value = null): void {
|
|
|
for($i = 1; $i <= 12; $i++) {
|
|
|
- $selected = ($selected_value == $i) ? "selected" : "";
|
|
|
+ $selected = ((int) $selected_value === $i) ? "selected" : "";
|
|
|
$display = date("M", mktime(0, 0, 0, $i, 15));
|
|
|
?>
|
|
|
<option value="<?=$i?>" <?=$selected?>><?=$display?></option>
|
|
|
@@ -78,43 +64,16 @@ class Form {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function renderDayOptions($selected_value = null) {
|
|
|
+ public static function renderDayOptions($selected_value = null): void {
|
|
|
for($i = 1; $i <= 31; $i++) {
|
|
|
- $selected = ($selected_value == $i) ? "selected" : "";
|
|
|
+ $selected = ((int) $selected_value === $i) ? "selected" : "";
|
|
|
?>
|
|
|
<option value="<?=$i?>" <?=$selected?>><?=$i?></option>
|
|
|
<?php
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function renderHourOptions($selected_value = null) {
|
|
|
- for($i = 0; $i <= 23; $i++) {
|
|
|
- $selected = ($selected_value === $i) ? "selected" : "";
|
|
|
- ?>
|
|
|
- <option value="<?=$i?>" <?=$selected?>><?=str_pad($i, 2, "0", STR_PAD_LEFT)?></option>
|
|
|
- <?php
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function renderMinuteOptions($selected_value = null) {
|
|
|
- for($i = 0; $i <= 59; $i++) {
|
|
|
- $selected = ($selected_value === $i) ? "selected" : "";
|
|
|
- ?>
|
|
|
- <option value="<?=$i?>" <?=$selected?>><?=str_pad($i, 2, "0", STR_PAD_LEFT)?></option>
|
|
|
- <?php
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function renderSecondOptions($selected_value = null) {
|
|
|
- for($i = 0; $i <= 59; $i++) {
|
|
|
- $selected = ($selected_value === $i) ? "selected" : "";
|
|
|
- ?>
|
|
|
- <option value="<?=$i?>" <?=$selected?>><?=str_pad($i, 2, "0", STR_PAD_LEFT)?></option>
|
|
|
- <?php
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static function renderCountryOptions($selected_value = null) {
|
|
|
+ public static function renderCountryOptions($selected_value = null): void {
|
|
|
|
|
|
$file = ROOT_DIR . "/files/countries.json";
|
|
|
$threshold = time() - (7 * 86400);
|
|
|
@@ -155,7 +114,7 @@ class Form {
|
|
|
* @param object $options
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public static function renderField(object $options) {
|
|
|
+ public static function renderField(object $options): void {
|
|
|
|
|
|
$required_key = $options->requiredKey ?? null;
|
|
|
|
|
|
@@ -211,9 +170,10 @@ class Form {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private static function renderHeader($options) {
|
|
|
+ private static function renderHeader($options): void {
|
|
|
+ $hidden = !empty($options->hidden) ? "hidden" : "";
|
|
|
?>
|
|
|
- <h3><?=htmlspecialchars($options->content)?></h3>
|
|
|
+ <h3 <?=$hidden?>><?=htmlspecialchars($options->content)?></h3>
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
@@ -221,15 +181,16 @@ class Form {
|
|
|
* @param object $options
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- private static function renderTextField(object $options) {
|
|
|
+ private static function renderTextField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$placeholder = "Enter " . strtolower($options->label);
|
|
|
$value = $options->value ?? http::value($options->name);
|
|
|
$required = ($options->required ?? false) ? "required" : "";
|
|
|
$help_text = $options->helpText ?? false;
|
|
|
$max_length = ($options->maxLength ?? false) ? "maxlength=\"$options->maxLength\"" : "";
|
|
|
+ $hidden = !empty($options->hidden) ? "hidden" : "";
|
|
|
?>
|
|
|
- <div class="form-group">
|
|
|
+ <div class="form-group" <?=$hidden?>>
|
|
|
<label for="<?=$id?>"><?=htmlspecialchars($options->label)?></label>
|
|
|
<input class="form-control" type="text" name="<?=$options->name?>" id="<?=$id?>" placeholder="<?=htmlspecialchars($placeholder)?>" value="<?=htmlspecialchars($value)?>" <?=$required?> <?=$max_length?> />
|
|
|
<?php
|
|
|
@@ -247,7 +208,7 @@ class Form {
|
|
|
* @param object $options
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- private static function renderNumberField(object $options) {
|
|
|
+ private static function renderNumberField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$placeholder = "Enter " . strtolower($options->label);
|
|
|
$value = $options->value ?? http::value($options->name);
|
|
|
@@ -258,9 +219,10 @@ class Form {
|
|
|
$max_length = ($options->maxLength ?? false) ? "maxlength=\"$options->maxLength\"" : "";
|
|
|
$step = $options->step ?? 1;
|
|
|
$prepend_text = $options->prependText ?? "";
|
|
|
+ $hidden = !empty($options->hidden) ? "hidden" : "";
|
|
|
|
|
|
?>
|
|
|
- <div class="form-group">
|
|
|
+ <div class="form-group" <?=$hidden?>>
|
|
|
<label for="<?=$id?>"><?=htmlspecialchars($options->label)?></label>
|
|
|
<div class="input-group">
|
|
|
<?php
|
|
|
@@ -289,7 +251,7 @@ class Form {
|
|
|
* @param object $options
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- private static function renderSelectField(object $options) {
|
|
|
+ private static function renderSelectField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$selected_value = $options->value ?? http::value($options->name);
|
|
|
$required = ($options->required ?? false) ? "required" : "";
|
|
|
@@ -302,7 +264,7 @@ class Form {
|
|
|
<?php
|
|
|
foreach($options->values as $index => $value) {
|
|
|
$display = $options->displayStrings[$index];
|
|
|
- $selected = ($selected_value === strval($value)) ? "selected" : "";
|
|
|
+ $selected = ($selected_value === (string) $value) ? "selected" : "";
|
|
|
?>
|
|
|
<option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
|
|
|
<?php
|
|
|
@@ -323,7 +285,7 @@ class Form {
|
|
|
/**
|
|
|
* @param object $options
|
|
|
*/
|
|
|
- private static function renderFileField(object $options) {
|
|
|
+ private static function renderFileField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$required = ($options->required ?? false) ? "required" : "";
|
|
|
$help_text = $options->helpText ?? false;
|
|
|
@@ -346,7 +308,7 @@ class Form {
|
|
|
* @param object $options
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- private static function renderTextareaField(object $options) {
|
|
|
+ private static function renderTextareaField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$placeholder = "Enter " . strtolower($options->label);
|
|
|
$value = $options->value ?? http::value($options->name);
|
|
|
@@ -368,13 +330,14 @@ class Form {
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
- private static function renderHorizontalBar(object $options) {
|
|
|
+ private static function renderHorizontalBar(object $options): void {
|
|
|
+ $hidden = !empty($options->hidden) ? "hidden" : "";
|
|
|
?>
|
|
|
- <hr />
|
|
|
+ <hr <?=$hidden?> />
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
- private static function renderCheckboxField(object $options) {
|
|
|
+ private static function renderCheckboxField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$checked = !empty($options->value) ? "checked" : "";
|
|
|
$required = ($options->required ?? false) ? "required" : "";
|
|
|
@@ -399,15 +362,20 @@ class Form {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private static function renderRadioField(object $options) {
|
|
|
+ /**
|
|
|
+ * @param object $options
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private static function renderRadioField(object $options): void {
|
|
|
$id = str_replace("_", "-", $options->name);
|
|
|
$current_value = $options->value ?? http::value($options->name);
|
|
|
$required = ($options->required ?? false) ? "required" : "";
|
|
|
$help_text = $options->helpText ?? false;
|
|
|
- $inline = ($options->type == "inline-radio") ? "custom-control-inline" : "";
|
|
|
+ $inline = ($options->type === "inline-radio") ? "custom-control-inline" : "";
|
|
|
+ $hidden = !empty($options->hidden) ? "hidden" : "";
|
|
|
|
|
|
?>
|
|
|
- <div class="form-group">
|
|
|
+ <div class="form-group" <?=$hidden?>>
|
|
|
<label>
|
|
|
<?=htmlspecialchars($options->label)?>
|
|
|
<?php
|
|
|
@@ -422,7 +390,7 @@ class Form {
|
|
|
<?php
|
|
|
foreach($options->values as $index => $value) {
|
|
|
$display = $options->displayStrings[$index];
|
|
|
- $checked = ($current_value === strval($value)) ? "checked" : "";
|
|
|
+ $checked = ($current_value === (string) $value) ? "checked" : "";
|
|
|
$radio_id = sprintf("%s-%s", $id, $value);
|
|
|
|
|
|
if($index === 0 && $current_value === null) {
|