From da40d88b1f2da18329a629289fd31112589affdb Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Sun, 24 Aug 2025 23:01:17 +0700
Subject: [PATCH 1/8] Add ToolTip (only use in custom form)
---
src/jojoe77777/FormAPI/CustomForm.php | 38 +++++++++++++++++----------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/src/jojoe77777/FormAPI/CustomForm.php b/src/jojoe77777/FormAPI/CustomForm.php
index 8ae6171..5b86efa 100755
--- a/src/jojoe77777/FormAPI/CustomForm.php
+++ b/src/jojoe77777/FormAPI/CustomForm.php
@@ -68,24 +68,29 @@ public function getTitle() : string {
public function addLabel(string $text, ?string $label = null) : self {
$this->addContent(["type" => "label", "text" => $text]);
$this->labelMap[] = $label ?? count($this->labelMap);
- $this->validationMethods[] = static fn($v) => $v === null;
+ // $this->validationMethods[] = static fn($v) => $v === null;
return $this;
}
/**
* @param string $text
* @param bool|null $default
+ * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addToggle(string $text, bool $default = null, ?string $label = null) : self {
+ public function addToggle(string $text, bool $default = null, string $tooltip = null, ?string $label = null) : self {
$content = ["type" => "toggle", "text" => $text];
if($default !== null) {
$content["default"] = $default;
}
+
+ if($tooltip !== null){
+ $content["tooltip"] = $tooltip;
+ }
+
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
- $this->validationMethods[] = static fn($v) => is_bool($v);
return $this;
}
@@ -95,10 +100,11 @@ public function addToggle(string $text, bool $default = null, ?string $label = n
* @param int $max
* @param int $step
* @param int $default
+ * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : self {
+ public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, string $tooltip = null, ?string $label = null) : self {
$content = ["type" => "slider", "text" => $text, "min" => $min, "max" => $max];
if($step !== -1) {
$content["step"] = $step;
@@ -106,9 +112,11 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
if($default !== -1) {
$content["default"] = $default;
}
+ if($tooltip !== null){
+ $content["tooltip"] = $tooltip;
+ }
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
- $this->validationMethods[] = static fn($v) => (is_float($v) || is_int($v)) && $v >= $min && $v <= $max;
return $this;
}
@@ -116,17 +124,20 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
* @param string $text
* @param array $steps
* @param int $defaultIndex
+ * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : self {
+ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, string $tooltip = null, ?string $label = null) : self {
$content = ["type" => "step_slider", "text" => $text, "steps" => $steps];
if($defaultIndex !== -1) {
$content["default"] = $defaultIndex;
}
+ if($tooltip !== null){
+ $content["tooltip"] = $tooltip;
+ }
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
- $this->validationMethods[] = static fn($v) => is_int($v) && isset($steps[$v]);
return $this;
}
@@ -134,13 +145,13 @@ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1
* @param string $text
* @param array $options
* @param int|null $default
+ * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : self {
- $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]);
+ public function addDropdown(string $text, array $options, int $default = null, string $tooltip = null, ?string $label = null) : self {
+ $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default, "tooltip" => $tooltip]);
$this->labelMap[] = $label ?? count($this->labelMap);
- $this->validationMethods[] = static fn($v) => is_int($v) && isset($options[$v]);
return $this;
}
@@ -148,13 +159,13 @@ public function addDropdown(string $text, array $options, int $default = null, ?
* @param string $text
* @param string $placeholder
* @param string|null $default
+ * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : self {
- $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]);
+ public function addInput(string $text, string $placeholder = "", string $default = null, string $tooltip = null, ?string $label = null) : self {
+ $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default, "tooltip" => $tooltip]);
$this->labelMap[] = $label ?? count($this->labelMap);
- $this->validationMethods[] = static fn($v) => is_string($v);
return $this;
}
@@ -166,5 +177,4 @@ private function addContent(array $content) : self {
$this->data["content"][] = $content;
return $this;
}
-
}
From b9f69496284d49471150cfc89637d8c2ad5c814d Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Sun, 24 Aug 2025 23:02:48 +0700
Subject: [PATCH 2/8] Add Header, Divider & setSubmitButton function
---
src/jojoe77777/FormAPI/Form.php | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/jojoe77777/FormAPI/Form.php b/src/jojoe77777/FormAPI/Form.php
index 12e248a..f5e0720 100755
--- a/src/jojoe77777/FormAPI/Form.php
+++ b/src/jojoe77777/FormAPI/Form.php
@@ -31,6 +31,25 @@ public function __construct(?callable $callable) {
public function sendToPlayer(Player $player) : void {
$player->sendForm($this);
}
+
+ /**
+ * @param string $text
+ */
+ public function addHeader(string $text) : void{
+ $this->data["content"][] = ["type" => "header", "text" => $text];
+ }
+
+ public function addDivider() : void{
+ $this->data["content"][] = ["type" => "divider", "text" => ""];
+ }
+
+ /**
+ * @param string $texr
+ * @return $this
+ */
+ public function setSubmitButton(string $text) : void{
+ $this->data["submit"] = $text;
+ }
public function getCallable() : ?callable {
return $this->callable;
From a0f83629c39b0800ee8be85686a4f5b140d06d5a Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Sun, 24 Aug 2025 23:48:22 +0700
Subject: [PATCH 3/8] Update README.md
---
README.md | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/README.md b/README.md
index 9054fe1..8b9d341 100644
--- a/README.md
+++ b/README.md
@@ -19,3 +19,38 @@ projects:
- src: jojoe77777/FormAPI/libFormAPI
version: ^2.1.1
```
+
+## Add Features
+### HEADER
+
+
+For Developers:
+```php
+$form->addHeader(string $text);
+```
+
+### TOOLTIP
+
+
+For Developers:
+```php
+$form->addToggle("input", "", "", "this is tooltip");
+$form->addDropDown("select", ["1", "2", "3"], 0, "this is tooltip dropdown");
+.....
+```
+
+### DIVIDER
+
+
+For Developers:
+```php
+$form->addDivider();
+```
+
+### SET CUSTOM SUBMIT BUTTON
+
+
+For Developers:
+```php
+$form->setSubmitButton(string $text);
+```
From 1a4e741e5cd8c3f08f225a7d25cc7cb30f5ba99e Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Tue, 14 Oct 2025 23:05:49 +0700
Subject: [PATCH 4/8] Move addHeader() and addDivider() to CustomForm.php
---
src/jojoe77777/FormAPI/Form.php | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/src/jojoe77777/FormAPI/Form.php b/src/jojoe77777/FormAPI/Form.php
index f5e0720..ccd6ee2 100755
--- a/src/jojoe77777/FormAPI/Form.php
+++ b/src/jojoe77777/FormAPI/Form.php
@@ -31,22 +31,10 @@ public function __construct(?callable $callable) {
public function sendToPlayer(Player $player) : void {
$player->sendForm($this);
}
-
+
/**
* @param string $text
*/
- public function addHeader(string $text) : void{
- $this->data["content"][] = ["type" => "header", "text" => $text];
- }
-
- public function addDivider() : void{
- $this->data["content"][] = ["type" => "divider", "text" => ""];
- }
-
- /**
- * @param string $texr
- * @return $this
- */
public function setSubmitButton(string $text) : void{
$this->data["submit"] = $text;
}
From ebd40cd9ed05cff687841e32827a4ab3ffecfeb9 Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Tue, 14 Oct 2025 23:10:12 +0700
Subject: [PATCH 5/8] Receive AddHeader() and AddDivider() from Form.php
---
src/jojoe77777/FormAPI/CustomForm.php | 53 +++++++++++++++++----------
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/src/jojoe77777/FormAPI/CustomForm.php b/src/jojoe77777/FormAPI/CustomForm.php
index 5b86efa..8b39dfb 100755
--- a/src/jojoe77777/FormAPI/CustomForm.php
+++ b/src/jojoe77777/FormAPI/CustomForm.php
@@ -26,7 +26,7 @@ public function processData(&$data) : void {
throw new FormValidationException("Expected an array response, got " . gettype($data));
}
if(is_array($data)) {
- if(count($data) !== count($this->validationMethods)) {
+ if(count($data) > count($this->validationMethods)) {
throw new FormValidationException("Expected an array response with the size " . count($this->validationMethods) . ", got " . count($data));
}
$new = [];
@@ -68,14 +68,13 @@ public function getTitle() : string {
public function addLabel(string $text, ?string $label = null) : self {
$this->addContent(["type" => "label", "text" => $text]);
$this->labelMap[] = $label ?? count($this->labelMap);
- // $this->validationMethods[] = static fn($v) => $v === null;
+ $this->validationMethods[] = static fn($v) => $v === null;
return $this;
}
/**
* @param string $text
* @param bool|null $default
- * @param string $tooltip
* @param string|null $label
* @return $this
*/
@@ -91,6 +90,7 @@ public function addToggle(string $text, bool $default = null, string $tooltip =
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => is_bool($v);
return $this;
}
@@ -100,11 +100,10 @@ public function addToggle(string $text, bool $default = null, string $tooltip =
* @param int $max
* @param int $step
* @param int $default
- * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, string $tooltip = null, ?string $label = null) : self {
+ public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : self {
$content = ["type" => "slider", "text" => $text, "min" => $min, "max" => $max];
if($step !== -1) {
$content["step"] = $step;
@@ -112,11 +111,9 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
if($default !== -1) {
$content["default"] = $default;
}
- if($tooltip !== null){
- $content["tooltip"] = $tooltip;
- }
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => (is_float($v) || is_int($v)) && $v >= $min && $v <= $max;
return $this;
}
@@ -124,20 +121,17 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
* @param string $text
* @param array $steps
* @param int $defaultIndex
- * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, string $tooltip = null, ?string $label = null) : self {
+ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : self {
$content = ["type" => "step_slider", "text" => $text, "steps" => $steps];
if($defaultIndex !== -1) {
$content["default"] = $defaultIndex;
}
- if($tooltip !== null){
- $content["tooltip"] = $tooltip;
- }
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => is_int($v) && isset($steps[$v]);
return $this;
}
@@ -145,13 +139,13 @@ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1
* @param string $text
* @param array $options
* @param int|null $default
- * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addDropdown(string $text, array $options, int $default = null, string $tooltip = null, ?string $label = null) : self {
- $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default, "tooltip" => $tooltip]);
+ public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : self {
+ $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]);
$this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => is_int($v) && isset($options[$v]);
return $this;
}
@@ -159,15 +153,36 @@ public function addDropdown(string $text, array $options, int $default = null, s
* @param string $text
* @param string $placeholder
* @param string|null $default
- * @param string $tooltip
* @param string|null $label
* @return $this
*/
- public function addInput(string $text, string $placeholder = "", string $default = null, string $tooltip = null, ?string $label = null) : self {
- $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default, "tooltip" => $tooltip]);
+ public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : self {
+ $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]);
$this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => is_string($v);
return $this;
}
+
+ /**
+ * @param string $text
+ * @return $this
+ */
+ public function addHeader(string $text, ?string $label = null) : self{
+ $this->addContent(["type" => "header", "text" => $text]);
+ $this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => $v === null;
+ return $this;
+ }
+
+ /**
+ * @return $this
+ */
+ public function addDivider(?string $label = null) : self{
+ $this->addContent(["type" => "divider", "text" => ""]);
+ $this->labelMap[] = $label ?? count($this->labelMap);
+ $this->validationMethods[] = static fn($v) => $v === null;
+ return $this;
+ }
/**
* @param array $content
From 4a1d30a0db60b6ab0ed9d23a36f44f53bbd092c2 Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Tue, 14 Oct 2025 23:11:52 +0700
Subject: [PATCH 6/8] Receive AddHeader() and AddDivider() from Form.php
---
src/jojoe77777/FormAPI/CustomForm.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/jojoe77777/FormAPI/CustomForm.php b/src/jojoe77777/FormAPI/CustomForm.php
index 8b39dfb..9c0a5bd 100755
--- a/src/jojoe77777/FormAPI/CustomForm.php
+++ b/src/jojoe77777/FormAPI/CustomForm.php
@@ -26,7 +26,7 @@ public function processData(&$data) : void {
throw new FormValidationException("Expected an array response, got " . gettype($data));
}
if(is_array($data)) {
- if(count($data) > count($this->validationMethods)) {
+ if(count($data) !== count($this->validationMethods)) {
throw new FormValidationException("Expected an array response with the size " . count($this->validationMethods) . ", got " . count($data));
}
$new = [];
From 26fb9007c4d173c413472eb4a4f4edc57162d3fd Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Tue, 14 Oct 2025 23:46:07 +0700
Subject: [PATCH 7/8] Add ToolTip back to CustomForm because I accidentally
deleted it :((
---
src/jojoe77777/FormAPI/CustomForm.php | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/jojoe77777/FormAPI/CustomForm.php b/src/jojoe77777/FormAPI/CustomForm.php
index 9c0a5bd..a24a255 100755
--- a/src/jojoe77777/FormAPI/CustomForm.php
+++ b/src/jojoe77777/FormAPI/CustomForm.php
@@ -75,6 +75,7 @@ public function addLabel(string $text, ?string $label = null) : self {
/**
* @param string $text
* @param bool|null $default
+ * @parm string|null $tooltip
* @param string|null $label
* @return $this
*/
@@ -100,10 +101,11 @@ public function addToggle(string $text, bool $default = null, string $tooltip =
* @param int $max
* @param int $step
* @param int $default
+ * @param string|null $tooltip
* @param string|null $label
* @return $this
*/
- public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : self {
+ public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, string $tooltip = null, ?string $label = null) : self {
$content = ["type" => "slider", "text" => $text, "min" => $min, "max" => $max];
if($step !== -1) {
$content["step"] = $step;
@@ -111,6 +113,9 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
if($default !== -1) {
$content["default"] = $default;
}
+ if($tooltip !== null){
+ $content["tooltip"] = $tooltip;
+ }
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
$this->validationMethods[] = static fn($v) => (is_float($v) || is_int($v)) && $v >= $min && $v <= $max;
@@ -121,14 +126,18 @@ public function addSlider(string $text, int $min, int $max, int $step = -1, int
* @param string $text
* @param array $steps
* @param int $defaultIndex
+ * @param string|null $tooltip
* @param string|null $label
* @return $this
*/
- public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : self {
+ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, string $tooltip = null, ?string $label = null) : self {
$content = ["type" => "step_slider", "text" => $text, "steps" => $steps];
if($defaultIndex !== -1) {
$content["default"] = $defaultIndex;
}
+ if($tooltip !== null){
+ $content["tooltip"] = $tooltip;
+ }
$this->addContent($content);
$this->labelMap[] = $label ?? count($this->labelMap);
$this->validationMethods[] = static fn($v) => is_int($v) && isset($steps[$v]);
@@ -139,11 +148,12 @@ public function addStepSlider(string $text, array $steps, int $defaultIndex = -1
* @param string $text
* @param array $options
* @param int|null $default
+ * @param string|null $tooltip
* @param string|null $label
* @return $this
*/
- public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : self {
- $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]);
+ public function addDropdown(string $text, array $options, int $default = null, string $tooltip = null, ?string $label = null) : self {
+ $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default, "tooltip" => $tooltip]);
$this->labelMap[] = $label ?? count($this->labelMap);
$this->validationMethods[] = static fn($v) => is_int($v) && isset($options[$v]);
return $this;
@@ -153,11 +163,12 @@ public function addDropdown(string $text, array $options, int $default = null, ?
* @param string $text
* @param string $placeholder
* @param string|null $default
+ * @param string|null $tooltip
* @param string|null $label
* @return $this
*/
- public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : self {
- $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]);
+ public function addInput(string $text, string $placeholder = "", string $default = null, string $tooltip = null, ?string $label = null) : self {
+ $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default, "tooltip" => $tooltip]);
$this->labelMap[] = $label ?? count($this->labelMap);
$this->validationMethods[] = static fn($v) => is_string($v);
return $this;
From 98530837b638e7d99bbcc6e689c0cf7ba7246091 Mon Sep 17 00:00:00 2001
From: ClickedTran_VN <58399779+ClickedTran@users.noreply.github.com>
Date: Wed, 15 Oct 2025 00:30:06 +0700
Subject: [PATCH 8/8] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 8b9d341..0026370 100644
--- a/README.md
+++ b/README.md
@@ -54,3 +54,4 @@ For Developers:
```php
$form->setSubmitButton(string $text);
```
+[