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..b2202e6 100644 --- a/models/Form.php +++ b/models/Form.php @@ -10,24 +10,36 @@ class Form { public $request_method; public $request_url; - public $content_above; - public $content_below; + private $fields = []; + public $before_fields; + public $after_fields; + + private $submit_caption; + public $buttons_extra; + 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->content_below = !empty($options['content_below']) ? $options['content_below'] : 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']); + 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() diff --git a/templates/FormView.php b/templates/FormView.php index 0f1f809..7e2bc1a 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 ' @@ -31,34 +31,29 @@ 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(); 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); } + if (isset($this->form->after_fields)) + echo $this->form->after_fields; + echo '
'; - if (isset($this->form->content_below)) + if (isset($this->form->buttons_extra)) echo ' - ', $this->form->content_below; + ', $this->form->buttons_extra; echo '
@@ -75,10 +70,8 @@ class FormView extends SubTemplate echo '
'; - if (isset($field['before'])) - echo $field['before']; - if ($field['type'] !== 'checkbox') + { if (isset($field['label'])) echo ' @@ -86,6 +79,7 @@ class FormView extends SubTemplate else echo '
'; + } switch ($field['type']) { @@ -127,15 +121,16 @@ class FormView extends SubTemplate $this->renderText($field_id, $field); } - if (isset($field['after'])) - echo ' ', $field['after']; - if ($field['type'] !== 'checkbox') echo '
'; echo '
'; + + if (isset($field['after_html'])) + echo ' + ', $field['after_html']; } private function renderCaptcha($field_id, array $field)