From fc581d26befbdaf06b8aa233e78bf8cce987d8a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 14 Apr 2018 20:48:21 +0200 Subject: [PATCH] Continued: - started porting to Bootstrap4 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../html/forms/class_HtmlFormHelper.php | 99 ++++++++++++------- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php b/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php index 7927b353..34e89307 100644 --- a/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php +++ b/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php @@ -43,10 +43,15 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { private $formOpened = false; /** - * Name of the form + * Name of current form */ private $formName = ''; + /** + * Id of current form + */ + private $formId = ''; + /** * Whether form tag is enabled (default: true) */ @@ -128,23 +133,18 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { // Check whether we shall open or close the form if (($this->formOpened === false) && ($this->formEnabled === true)) { // Add HTML code - $formContent = sprintf("
", $formName, $this->getConfigInstance()->getConfigEntry('base_url'), $this->getConfigInstance()->getConfigEntry('form_action'), $this->getConfigInstance()->getConfigEntry('form_method'), - $this->getConfigInstance()->getConfigEntry('form_target') - ); - - // Add form id as well - $formContent .= sprintf(" id=\"%s_form\"", + $this->getConfigInstance()->getConfigEntry('form_target'), $formId ); - // Add close bracket - $formContent .= '>'; - - // Open the form and remeber the form name + // Open the form and remeber the form name and id + $this->formName = $formName; + $this->formId = $formId; $this->formOpened = true; // Add it to the content @@ -161,6 +161,8 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { // Simply close it $this->formOpened = false; + $this->formName = ''; + $this->formId = ''; // Add it to the content $this->addFooterContent($formContent); @@ -184,7 +186,8 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } // END - if // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf('', + $this->getFormId(), $fieldName, $fieldName, $fieldValue @@ -226,7 +229,8 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } // END - if // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf('', + $this->getFormId(), $fieldName, $fieldName, $fieldValue @@ -253,7 +257,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } // END - if // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf('', $fieldName, $fieldValue ); @@ -310,11 +314,12 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } // END - if // Set whether the check box is checked... - $checked = " checked=\"checked\""; + $checked = ' checked="checked"'; if ($fieldChecked === false) $checked = ' '; // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf('', + $this->getFormId(), $fieldName, $fieldName, $checked @@ -340,8 +345,8 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } // END - if // Generate the content - $inputContent = sprintf("", - $this->getFormName(), + $inputContent = sprintf('', + $this->getFormId(), $buttonText ); @@ -365,9 +370,9 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } // END - if // Generate the content - $inputContent = sprintf("", - $this->getFormName(), - $this->getFormName(), + $inputContent = sprintf('', + $this->getFormId(), + $this->getFormId(), $buttonText ); @@ -511,33 +516,38 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { } /** - * Add text surrounded by a span block when there is a group opened before - * or else by a div block. + * Adds text surrounded by a label tag for given form field * - * @param $fieldName Field name - * @param $fieldText Text for the field + * @param $fieldName Field name + * @param $fieldText Text for the field + * @param $fieldTitle Optional title for label tag * @return void * @throws FormClosedException If the form is not yet opened */ - public function addFieldText ($fieldName, $fieldText) { + public function addFieldLabel ($fieldName, $fieldText, $fieldTitle = '') { // Is the form opened? if (($this->formOpened === false) && ($this->formEnabled === true)) { // Throw an exception throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM); } // END - if - // Set the block type - $block = 'div'; - if ($this->ifGroupOpenedPreviously()) $block = 'span'; + // Default is no title attribute + $titleAttribute = ''; + + // Is title given? + if (!empty($fieldTitle)) { + // Create title attribute + $titleAttribute = sprintf(' title="%s" data-toggle="tooltip"', $fieldTitle); + } // END - if // Generate the content - $inputContent = sprintf(" <%s id=\"%s_text\"> - %s - ", - $block, + $inputContent = sprintf('', + $this->getFormId(), $fieldName, - $fieldText, - $block + $titleAttribute, + $fieldText ); // And add it @@ -733,6 +743,25 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { return $this->formName; } + /** + * Setter for form id + * + * @param $formId Id of this form + * @return void + */ + public final function setFormId ($formId) { + $this->formId = (string) $formId; + } + + /** + * Getter for form id + * + * @return $formId Id of this form + */ + public final function getFormId () { + return $this->formId; + } + /** * Checks whether the registration requires a valid email address * -- 2.39.5