]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 14 Apr 2018 18:48:21 +0000 (20:48 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 14 Apr 2018 18:48:21 +0000 (20:48 +0200)
- started porting to Bootstrap4

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/helper/html/forms/class_HtmlFormHelper.php

index 7927b353a084340ca40f8a494c30f00e64c0c7a6..34e8930764ba46fc8312d995e81b4f881187b7e7 100644 (file)
@@ -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("<form name=\"%s\" class=\"forms\" action=\"%s/%s\" method=\"%s\" target=\"%s\"",
+                       $formContent = sprintf("<form name=\"%s\" class=\"forms\" action=\"%s/%s\" method=\"%s\" target=\"%s\" id=\"%s_form\">",
                                $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("<input type=\"text\" class=\"textfield %s_field\" name=\"%s\" value=\"%s\" />",
+               $inputContent = sprintf('<input type="text" class="form-control" id="%s_%s_field" name="%s" value="%s" />',
+                       $this->getFormId(),
                        $fieldName,
                        $fieldName,
                        $fieldValue
@@ -226,7 +229,8 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                } // END - if
 
                // Generate the content
-               $inputContent = sprintf("<input type=\"password\" class=\"password %s_field\" name=\"%s\" value=\"%s\" />",
+               $inputContent = sprintf('<input type="password" class="form-control" id="%s_%s_field" name="%s" value="%s" />',
+                       $this->getFormId(),
                        $fieldName,
                        $fieldName,
                        $fieldValue
@@ -253,7 +257,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                } // END - if
 
                // Generate the content
-               $inputContent = sprintf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />",
+               $inputContent = sprintf('<input type="hidden" name="%s" value="%s" />',
                        $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("<input type=\"checkbox\" name=\"%s\" class=\"checkbox %s_field\" value=\"1\"%s/>",
+               $inputContent = sprintf('<input type="checkbox" name="%s" class="checkbox" id="%s_%s_field" value="1"%s />',
+                       $this->getFormId(),
                        $fieldName,
                        $fieldName,
                        $checked
@@ -340,8 +345,8 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                } // END - if
 
                // Generate the content
-               $inputContent = sprintf("<input type=\"reset\" class=\"reset_button\" id=\"%s_reset\" value=\"%s\" />",
-                       $this->getFormName(),
+               $inputContent = sprintf('<input type="reset" class="reset_button" id="%s_reset" value="%s" />',
+                       $this->getFormId(),
                        $buttonText
                );
 
@@ -365,9 +370,9 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
                } // END - if
 
                // Generate the content
-               $inputContent = sprintf("<input type=\"submit\" class=\"submit_button\" id=\"%s_submit\" name=\"%s_button\" value=\"%s\" />",
-                       $this->getFormName(),
-                       $this->getFormName(),
+               $inputContent = sprintf('<input type="submit" class="submit_button" id="%s_submit" name="%s_submit" value="%s" />',
+                       $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
-       </%s>",
-                       $block,
+               $inputContent = sprintf('<label class="control-label" for="%s_%s_field"%s>
+       %s
+</label>',
+                       $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
         *