From 416cb730694a8ee9038615f4182c2c0bac006d63 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 19:57:12 +0200 Subject: [PATCH 1/7] FormView: remove unused $exclude and $include field lists --- templates/FormView.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/templates/FormView.php b/templates/FormView.php index 0f1f809..4ae2066 100644 --- a/templates/FormView.php +++ b/templates/FormView.php @@ -19,7 +19,7 @@ class FormView extends SubTemplate $this->title = $title; } - protected function html_content($exclude = [], $include = []) + protected function html_content() { if (!empty($this->title)) echo ' @@ -39,14 +39,6 @@ class FormView extends SubTemplate foreach ($this->form->getFields() as $field_id => $field) { - // Either we have a blacklist - if (!empty($exclude) && in_array($field_id, $exclude)) - continue; - // ... or a whitelist - elseif (!empty($include) && !in_array($field_id, $include)) - continue; - // ... or neither (ha) - $this->renderField($field_id, $field); } -- 2.49.0 From 12352c0d719fd1f9b734898d13d60d04d1a5f8ac Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 19:57:45 +0200 Subject: [PATCH 2/7] FormView: remove unused 'before' and 'after' properties --- templates/FormView.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/templates/FormView.php b/templates/FormView.php index 4ae2066..bd29788 100644 --- a/templates/FormView.php +++ b/templates/FormView.php @@ -67,9 +67,6 @@ class FormView extends SubTemplate echo '
'; - if (isset($field['before'])) - echo $field['before']; - if ($field['type'] !== 'checkbox') if (isset($field['label'])) echo ' @@ -119,9 +116,6 @@ class FormView extends SubTemplate $this->renderText($field_id, $field); } - if (isset($field['after'])) - echo ' ', $field['after']; - if ($field['type'] !== 'checkbox') echo '
'; -- 2.49.0 From 094fa16e787dabd150e6f6338252b644aa86be02 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 19:58:35 +0200 Subject: [PATCH 3/7] FormView: add 'after_html' equivalent to 'before_html' --- templates/FormView.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/FormView.php b/templates/FormView.php index bd29788..69254e9 100644 --- a/templates/FormView.php +++ b/templates/FormView.php @@ -68,6 +68,7 @@ class FormView extends SubTemplate
'; if ($field['type'] !== 'checkbox') + { if (isset($field['label'])) echo ' @@ -75,6 +76,7 @@ class FormView extends SubTemplate else echo '
'; + } switch ($field['type']) { @@ -122,6 +124,10 @@ class FormView extends SubTemplate echo '
'; + + if (isset($field['after_html'])) + echo ' + ', $field['after_html']; } private function renderCaptcha($field_id, array $field) -- 2.49.0 From be519464363959ab0e35cad16fbe96fa51dfb7a2 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 19:59:30 +0200 Subject: [PATCH 4/7] Form: rename 'content_below' to 'buttons_extra' --- controllers/EditAlbum.php | 2 +- controllers/EditTag.php | 2 +- controllers/EditUser.php | 2 +- models/Form.php | 4 ++-- templates/FormView.php | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/EditAlbum.php b/controllers/EditAlbum.php index 9691148..eb7a4c9 100644 --- a/controllers/EditAlbum.php +++ b/controllers/EditAlbum.php @@ -122,7 +122,7 @@ class EditAlbum extends HTMLController $this->form = new Form([ 'request_url' => BASEURL . '/editalbum/?' . ($id_tag ? 'id=' . $id_tag : 'add'), - 'content_below' => $after_form, + 'buttons_extra' => $after_form, 'fields' => $fields, ]); diff --git a/controllers/EditTag.php b/controllers/EditTag.php index 116d226..00ce7d3 100644 --- a/controllers/EditTag.php +++ b/controllers/EditTag.php @@ -106,7 +106,7 @@ class EditTag extends HTMLController $form = new Form([ 'request_url' => BASEURL . '/edittag/?' . ($id_tag ? 'id=' . $id_tag : 'add'), - 'content_below' => $after_form, + 'buttons_extra' => $after_form, 'fields' => $fields, ]); diff --git a/controllers/EditUser.php b/controllers/EditUser.php index 39715e9..089dca6 100644 --- a/controllers/EditUser.php +++ b/controllers/EditUser.php @@ -69,7 +69,7 @@ class EditUser extends HTMLController $form = new Form([ 'request_url' => BASEURL . '/edituser/?' . ($id_user ? 'id=' . $id_user : 'add'), - 'content_below' => $after_form, + 'buttons_extra' => $after_form, 'fields' => [ 'first_name' => [ 'type' => 'text', diff --git a/models/Form.php b/models/Form.php index e61b986..d006907 100644 --- a/models/Form.php +++ b/models/Form.php @@ -11,7 +11,7 @@ class Form public $request_method; public $request_url; public $content_above; - public $content_below; + public $buttons_extra; private $fields = []; private $data = []; private $missing = []; @@ -24,7 +24,7 @@ class Form $this->request_method = !empty($options['request_method']) ? $options['request_method'] : 'POST'; $this->request_url = !empty($options['request_url']) ? $options['request_url'] : BASEURL; $this->fields = !empty($options['fields']) ? $options['fields'] : []; - $this->content_below = !empty($options['content_below']) ? $options['content_below'] : null; + $this->buttons_extra = !empty($options['buttons_extra']) ? $options['buttons_extra'] : null; $this->content_above = !empty($options['content_above']) ? $options['content_above'] : null; $this->submit_caption = !empty($options['submit_caption']) ? $options['submit_caption'] : 'Save information'; $this->trim_inputs = !empty($options['trim_inputs']); diff --git a/templates/FormView.php b/templates/FormView.php index 69254e9..044f395 100644 --- a/templates/FormView.php +++ b/templates/FormView.php @@ -48,9 +48,9 @@ class FormView extends SubTemplate
'; - if (isset($this->form->content_below)) + if (isset($this->form->buttons_extra)) echo ' - ', $this->form->content_below; + ', $this->form->buttons_extra; echo '
-- 2.49.0 From f88d1885a2ff0366309ce3a2c11d61593423f89a Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 19:59:53 +0200 Subject: [PATCH 5/7] Form: rename 'content_above' to 'before_fields' --- models/Form.php | 4 ++-- templates/FormView.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/Form.php b/models/Form.php index d006907..53549a0 100644 --- a/models/Form.php +++ b/models/Form.php @@ -10,7 +10,7 @@ class Form { public $request_method; public $request_url; - public $content_above; + public $before_fields; public $buttons_extra; private $fields = []; private $data = []; @@ -25,7 +25,7 @@ class Form $this->request_url = !empty($options['request_url']) ? $options['request_url'] : BASEURL; $this->fields = !empty($options['fields']) ? $options['fields'] : []; $this->buttons_extra = !empty($options['buttons_extra']) ? $options['buttons_extra'] : null; - $this->content_above = !empty($options['content_above']) ? $options['content_above'] : null; + $this->before_fields = !empty($options['before_fields']) ? $options['before_fields'] : null; $this->submit_caption = !empty($options['submit_caption']) ? $options['submit_caption'] : 'Save information'; $this->trim_inputs = !empty($options['trim_inputs']); } diff --git a/templates/FormView.php b/templates/FormView.php index 044f395..ebc5321 100644 --- a/templates/FormView.php +++ b/templates/FormView.php @@ -31,8 +31,8 @@ class FormView extends SubTemplate echo '
'; - if (isset($this->form->content_above)) - echo $this->form->content_above; + if (isset($this->form->before_fields)) + echo $this->form->before_fields; $this->missing = $this->form->getMissing(); $this->data = $this->form->getData(); -- 2.49.0 From e69139e591e9837519c75cfa5a2ef9b9cf7a9628 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 20:00:22 +0200 Subject: [PATCH 6/7] Form: introduce 'after_fields' content as well --- models/Form.php | 2 ++ templates/FormView.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/models/Form.php b/models/Form.php index 53549a0..020716a 100644 --- a/models/Form.php +++ b/models/Form.php @@ -11,6 +11,7 @@ class Form public $request_method; public $request_url; public $before_fields; + public $after_fields; public $buttons_extra; private $fields = []; private $data = []; @@ -26,6 +27,7 @@ class Form $this->fields = !empty($options['fields']) ? $options['fields'] : []; $this->buttons_extra = !empty($options['buttons_extra']) ? $options['buttons_extra'] : null; $this->before_fields = !empty($options['before_fields']) ? $options['before_fields'] : null; + $this->after_fields = !empty($options['after_fields']) ? $options['after_fields'] : null; $this->submit_caption = !empty($options['submit_caption']) ? $options['submit_caption'] : 'Save information'; $this->trim_inputs = !empty($options['trim_inputs']); } diff --git a/templates/FormView.php b/templates/FormView.php index ebc5321..7e2bc1a 100644 --- a/templates/FormView.php +++ b/templates/FormView.php @@ -42,6 +42,9 @@ class FormView extends SubTemplate $this->renderField($field_id, $field); } + if (isset($this->form->after_fields)) + echo $this->form->after_fields; + echo '
-- 2.49.0 From 8373c5d2d522b56744e99da08799603ebfac4e81 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Sep 2025 20:01:36 +0200 Subject: [PATCH 7/7] Form: reorder class properties and rework constructor --- models/Form.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/models/Form.php b/models/Form.php index 020716a..b2202e6 100644 --- a/models/Form.php +++ b/models/Form.php @@ -10,26 +10,36 @@ class Form { public $request_method; public $request_url; + + private $fields = []; public $before_fields; public $after_fields; + + private $submit_caption; public $buttons_extra; - private $fields = []; + private $trim_inputs; + private $data = []; private $missing = []; - private $submit_caption; - private $trim_inputs; // NOTE: this class does not verify the completeness of form options. public function __construct($options) { - $this->request_method = !empty($options['request_method']) ? $options['request_method'] : 'POST'; - $this->request_url = !empty($options['request_url']) ? $options['request_url'] : BASEURL; - $this->fields = !empty($options['fields']) ? $options['fields'] : []; - $this->buttons_extra = !empty($options['buttons_extra']) ? $options['buttons_extra'] : null; - $this->before_fields = !empty($options['before_fields']) ? $options['before_fields'] : null; - $this->after_fields = !empty($options['after_fields']) ? $options['after_fields'] : null; - $this->submit_caption = !empty($options['submit_caption']) ? $options['submit_caption'] : 'Save information'; - $this->trim_inputs = !empty($options['trim_inputs']); + static $optionKeys = [ + 'request_method' => 'POST', + 'request_url' => BASEURL, + + 'fields' => [], + 'before_fields' => null, + 'after_fields' => null, + + 'submit_caption' => 'Save information', + 'buttons_extra' => null, + 'trim_inputs' => true, + ]; + + foreach ($optionKeys as $optionKey => $default) + $this->$optionKey = !empty($options[$optionKey]) ? $options[$optionKey] : $default; } public function getFields() -- 2.49.0