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)
*/
// 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
// Simply close it
$this->formOpened = false;
+ $this->formName = '';
+ $this->formId = '';
// Add it to the content
$this->addFooterContent($formContent);
} // 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
} // 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
} // 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
);
} // 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
} // 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
);
} // 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
);
}
/**
- * 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
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
*