]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/helper/html/forms/class_HtmlFormHelper.php
Continued:
[core.git] / framework / main / classes / helper / html / forms / class_HtmlFormHelper.php
index acfb8d0d66e2ff6535554acb40a29b9907c3becb..30549f57325747ec9fc45383c07ecd047fe5f907 100644 (file)
@@ -7,7 +7,7 @@ use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseWrapper;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Helper\Template\HelpableTemplate;
-use Org\Mxchange\CoreFramework\Registry\Registry;
+use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
 
 // Import SPL stuff
@@ -18,11 +18,7 @@ use \InvalidArgumentException;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
-<<<<<<< HEAD:framework/main/classes/helper/html/forms/class_HtmlFormHelper.php
  * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
-=======
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
->>>>>>> Some updates::inc/main/classes/helper/html/forms/class_HtmlFormHelper.php
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -47,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)
         */
@@ -132,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
@@ -188,7 +184,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
@@ -230,7 +227,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
@@ -257,7 +255,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
                );
@@ -314,11 +312,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
@@ -344,8 +343,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
                );
 
@@ -369,9 +368,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
                );
 
@@ -515,33 +514,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="col-form-label" for="%s_%s_field"%s>
+       %s
+</label>',
+                       $this->getFormId(),
                        $fieldName,
-                       $fieldText,
-                       $block
+                       $titleAttribute,
+                       $fieldText
                );
 
                // And add it
@@ -689,7 +693,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate {
 
                try {
                        // Get last executed pre filter
-                       $extraInstance = Registry::getRegistry()->getInstance('extra');
+                       $extraInstance = GenericRegistry::getRegistry()->getInstance('extra');
                } catch (NullPointerException $e) {
                        // Instance in registry is not set (NULL)
                        // @TODO We need to log this later
@@ -737,6 +741,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
         *