From 693670c013355e9e0de3d6806cd0cb68869a10a6 Mon Sep 17 00:00:00 2001 From: attemx <128401363+attemx@users.noreply.github.com> Date: Sat, 1 Apr 2023 10:53:42 -0600 Subject: [PATCH 1/2] Update FormBuilder.php Add support to array fields, example: Form::text("data[name]","Name") formDataFill: "data"=>["name"="John"] --- src/FormBuilder.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index ce7ed23..c61805a 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -430,11 +430,28 @@ private function getValue() } } - $fromFill = $formData[$name] ?? null; - + if(str_contains($name,'[')) { + $name = str_replace("]","",str_replace("[",".",str_replace("][",".",$name))); + } + if(str_contains($name,'.')){ + $fromFill = $this->get_multi($formData,$name); + }else { + $fromFill = $formData[$name] ?? null; + } return $value ?? $fromFill; } + function get_multi($arr, $str) { + foreach (explode('.', $str) as $key) { + if (!array_key_exists($key, $arr)) { + return NULL; + } + $arr = $arr[$key]; + } + + return $arr; + } + private function buildHtmlAttrs(array $attributes, $appendAttrs = true): string { From 2b01a67a4e0e867b4be1f2eb3d6a310dd12b129c Mon Sep 17 00:00:00 2001 From: attemx <128401363+attemx@users.noreply.github.com> Date: Sun, 2 Apr 2023 12:11:59 -0600 Subject: [PATCH 2/2] Update FormBuilder.php Remove . from [] to treat ir as value and not array --- src/FormBuilder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index c61805a..aeb2405 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -432,6 +432,7 @@ private function getValue() if(str_contains($name,'[')) { $name = str_replace("]","",str_replace("[",".",str_replace("][",".",$name))); + $name = trim($name, '.'); } if(str_contains($name,'.')){ $fromFill = $this->get_multi($formData,$name);