*/
private $subGroupOpened = false;
+ /**
+ * Name of the group
+ */
+ private $groupName = "";
+
/**
* Name of the sub group
*/
private $formEnabled = true;
// Class Constants
- const EXCEPTION_FORM_NAME_INVALID = 0x030;
- const EXCEPTION_CLOSED_FORM = 0x031;
- const EXCEPTION_OPENED_FORM = 0x032;
- const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x033;
+ const EXCEPTION_FORM_NAME_INVALID = 0x120;
+ const EXCEPTION_CLOSED_FORM = 0x121;
+ const EXCEPTION_OPENED_FORM = 0x122;
+ const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x123;
/**
* Protected constructor
// Is a group open?
if ($this->groupOpened === true) {
// Then automatically close it here
- $this->addFormGroup("", "");
+ $this->addFormGroup();
} // END - if
// Simply close it
/**
* Add a form group or close an already opened and open a new one
*
- * @param $groupName Name of the group
+ * @param $groupName Name of the group or last opened if empty
* @param $groupText Text including HTML to show above this group
* @return void
* @throws FormClosedException If no form has been opened before
* @throws EmptyVariableException If $groupName is not set
*/
- public function addFormGroup ($groupName, $groupText) {
+ public function addFormGroup ($groupName = "", $groupText = "") {
// Is a form opened?
if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw exception here
if ((empty($groupName)) && ($this->groupOpened === false)) {
// Throw exception here
throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (empty($groupName)) {
+ // Close the last opened
+ $groupName = $this->groupName;
+ }
+
+ // Same group to open?
+ if (($this->groupOpened === false) && ($groupName == $this->groupName)) {
+ // Abort here silently
+ return false;
} // END - if
// Initialize content with closing div by default
$this->addContent($content);
// Switch the state
+ $this->groupName = $groupName;
$this->groupOpened = true;
} else {
// Is a sub group opened?
if ($this->subGroupOpened === true) {
// Close it here
- $this->addFormSubGroup("", "");
+ $this->addFormSubGroup();
} // END - if
// Add the content
* throws an exception if no group has been opened before or if the sub
* group name is empty.
*
- * @param $subGroupName Name of the group
+ * @param $subGroupName Name of the group or last opened if empty
* @param $subGroupText Text including HTML to show above this group
* @return void
* @throws FormGroupClosedException If no group has been opened before
* @throws EmptyVariableException If $subGroupName is not set
*/
- public function addFormSubGroup ($subGroupName, $subGroupText) {
+ public function addFormSubGroup ($subGroupName = "", $subGroupText = "") {
// Is a group opened?
if ($this->groupOpened === false) {
// Throw exception here
if ((empty($subGroupName)) && ($this->subGroupOpened === false)) {
// Throw exception here
throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (empty($subGroupName)) {
+ // Close the last opened
+ $subGroupName = $this->subGroupName;
+ }
+
+ // Same sub group to open?
+ if (($this->subGroupOpened === false) && ($subGroupName == $this->subGroupName)) {
+ // Abort here silently
+ return false;
} // END - if
// Initialize content with closing div by default
* Add text (notes) surrounded by a div block. Still opened groups or sub
* groups will be automatically closed.
*
+ * @param $noteId Id for this note
* @param $formNotes The form notes we shell addd
* @return void
* @throws FormClosedException If the form is not yet opened
*/
- public function addFormNote ($formNotes) {
+ public function addFormNote ($noteId, $formNotes) {
// Is the form opened?
if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
// Is a group open?
if ($this->groupOpened === true) {
// Then automatically close it here
- $this->addFormGroup("", "");
+ $this->addFormGroup();
} // END - if
// Generate the content
- $inputContent = sprintf(" <div id=\"form_note\">
+ $inputContent = sprintf(" <div id=\"form_note_%s\">
%s
</div>",
+ $noteId,
$formNotes
);
if (($this->formOpened === true) && ($this->formEnabled === true)) {
// Close the form automatically
$this->addFormTag();
- } // END - if
+ } elseif ($this->formEnabled === false) {
+ if ($this->subGroupOpened === true) {
+ // Close sub group
+ $this->addFormSubGroup();
+ } elseif ($this->groupOpened === true) {
+ // Close group
+ $this->addFormGroup();
+ }
+ }
// Send content to template engine
+ //* DEBUG: */ echo __METHOD__.": form=".$this->getFormName().", size=".strlen($this->getContent())."<br />\n";
$this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
}
$extraInstance = Registry::getRegistry()->getInstance('extra');
// Get a configured instance
- $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this->getTemplateInstance(), $extraInstance));
+ $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this, $extraInstance));
// Initiate the CAPTCHA
$captchaInstance->initiateCaptcha();