* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class WebFormHelper extends BaseHelper {
+class WebFormHelper extends BaseHelper implements HelpableTemplate {
/**
* Instance to the class which provides field values
*/
*/
private $subGroupName = "";
+ /**
+ * Wether form tag is enabled (default: true)
+ */
+ private $formEnabled = true;
+
// Class Constants
const EXCEPTION_FORM_NAME_INVALID = 0x030;
const EXCEPTION_CLOSED_FORM = 0x031;
* @param $templateInstance An instance of a valid template engine
* @param $formName Name of the form
* @param $formId Value for "id" attribute (default: $formName)
+ * @param $withForm Wether include the form tag
* @return $helperInstance A preparedf instance of this class
*/
- public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) {
+ public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false, $withForm = true) {
// Get new instance
$helperInstance = new WebFormHelper();
if ($formId === false) {
// Use form id from form name
$formId = $formName;
- }
+ } // END - if
- // Create the form
- $helperInstance->addFormTag($formName, $formId);
+ // Set form name
+ $helperInstance->setFormName($formName);
+ // A form-less field may say "false" here...
+ if ($withForm === true) {
+ // Create the form
+ $helperInstance->addFormTag($formName, $formId);
+ } else {
+ // Disable form
+ $helperInstance->enableForm(false);
+ }
// Return the prepared instance
return $helperInstance;
$formContent = "</form>";
// Check wether we shall open or close the form
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Add HTML code
$formContent = sprintf("<form name=\"%s\" class=\"forms\" action=\"%s/%s\" method=\"%s\" target=\"%s\"",
$formName,
$this->getConfigInstance()->readConfig('form_target')
);
- // Is the form id set?
- if ($formId !== false) {
- // Then add it as well
- $formContent .= sprintf(" id=\"%s_form\"",
- $formId
- );
- }
+ // Add form id as well
+ $formContent .= sprintf(" id=\"%s_form\"",
+ $formId
+ );
// Add close bracket
$formContent .= ">";
// Open the form and remeber the form name
$this->formOpened = true;
- $this->formName = $formName;
} else {
// Add the hidden field required to identify safely this form
- $this->addInputHiddenField('form', $this->formName);
+ $this->addInputHiddenField('form', $this->getFormName());
// Is a group open?
if ($this->groupOpened === true) {
*/
public function addInputTextField ($fieldName, $fieldValue = "") {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
} // END - if
*/
public function addInputPasswordField ($fieldName, $fieldValue = "") {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
} // END - if
*/
public function addInputHiddenField ($fieldName, $fieldValue = "") {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
} // END - if
*/
public function addInputCheckboxField ($fieldName, $fieldChecked = true) {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
} // END - if
*/
public function addInputResetButton ($buttonText) {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, "reset"), self::EXCEPTION_CLOSED_FORM);
} // END - if
// Generate the content
$inputContent = sprintf("<input type=\"reset\" class=\"reset_button\" id=\"%s_reset\" value=\"%s\" />",
- $this->formName,
+ $this->getFormName(),
$buttonText
);
*/
public function addInputSubmitButton ($buttonText) {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, "submit"), self::EXCEPTION_CLOSED_FORM);
} // END - if
// Generate the content
$inputContent = sprintf("<input type=\"submit\" class=\"submit_button\" id=\"%s_submit\" name=\"%s_button\" value=\"%s\" />",
- $this->formName,
- $this->formName,
+ $this->getFormName(),
+ $this->getFormName(),
$buttonText
);
*/
public function addFormGroup ($groupName, $groupText) {
// Is a form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw exception here
throw new FormClosedException(array($this, $groupName), self::EXCEPTION_CLOSED_FORM);
} // END - if
*/
public function addFieldText ($fieldName, $fieldText) {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
} // END - if
*/
public function addFormNote ($formNotes) {
// Is the form opened?
- if ($this->formOpened === false) {
+ if (($this->formOpened === false) && ($this->formEnabled === true)) {
// Throw an exception
throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM);
} // END - if
* @return $isSecured Wether this form is secured by a CAPTCHA
*/
public function ifFormSecuredWithCaptcha () {
- $isSecured = ($this->getConfigInstance()->readConfig($this->formName."_captcha_secured") == "Y");
+ $isSecured = ($this->getConfigInstance()->readConfig($this->getFormName()."_captcha_secured") == "Y");
return $isSecured;
}
*/
public function flushContent () {
// Is the form still open?
- if ($this->formOpened === true) {
+ if (($this->formOpened === true) && ($this->formEnabled === true)) {
// Close the form automatically
$this->addFormTag();
} // END - if
// Send content to template engine
- $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent());
+ $this->getTemplateInstance()->assignVariable($this->getFormName(), $this->getContent());
}
/**
$extraInstance = Registry::getRegistry()->getInstance('extra');
// Get a configured instance
- $captchaInstance = ObjectFactory::createObjectByConfiguredName("{$this->formName}_captcha", array($this->getTemplateInstance(), $extraInstance));
+ $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName()."_captcha", array($this->getTemplateInstance(), $extraInstance));
// Initiate the CAPTCHA
$captchaInstance->initiateCaptcha();
// Get the content and add it to the helper
$this->addContent($captchaInstance->getContent());
}
+
+ /**
+ * Enables/disables the form tag usage
+ *
+ * @param $formEnabled Wether form is enabled or disabled
+ * @return void
+ */
+ public final function enableForm ($formEnabled = true) {
+ $this->formEnabled = (bool) $formEnabled;
+ }
+
+ /**
+ * Setter for form name
+ *
+ * @param $formName Name of this form
+ * @return void
+ */
+ public final function setFormName ($formName) {
+ $this->formName = (string) $formName;
+ }
+
+ /**
+ * Getter for form name
+ *
+ * @return $formName Name of this form
+ */
+ public final function getFormName () {
+ return $this->formName;
+ }
}
// [EOF]