* @version 0.0.0
* @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
class HtmlFormHelper extends BaseTemplateHelper {
/**
* Wether the form tag is opened (keep at false or else your forms will
* never work!)
*/
private $formOpened = false;
/**
* Name of the form
*/
private $formName = "";
/**
* Wether the group is opened or not
*/
private $groupOpened = false;
/**
* Wether the sub group is opened or not
*/
private $subGroupOpened = false;
// Class Constants
const EXCEPTION_FORM_NAME_INVALID = 0xb00;
const EXCEPTION_CLOSED_FORM = 0xb01;
const EXCEPTION_OPENED_FORM = 0xb02;
/**
* Private constructor
*
* @return void
*/
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
// Set part description
$this->setObjectDescription("HTML-Formularhilfsklasse");
}
/**
* Creates the helper class with the given template engine instance and form name
*
* @param $templateInstance An instance of a valid template engine
* @param $formName Name of the form
* @param $formId Value for "id" attribute (default: $formName)
* @return $helperInstance A preparedf instance of this class
*/
public final static function createHtmlFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) {
// Get new instance
$helperInstance = new HtmlFormHelper();
// Set template instance
$helperInstance->setTemplateInstance($templateInstance);
// Is the form id not set?
if ($formId === false) {
// Use form id from form name
$formId = $formName;
}
// Create the form
$helperInstance->addFormTag($formName, $formId);
// Return the prepared instance
return $helperInstance;
}
/**
* Add the form tag or close it an already opened form tag
*
* @param $formName Name of the form (default: false)
* @param $formId Id of the form (attribute "id"; default: false)
* @return void
* @throws InvalidFormNameException If the form name is invalid (=false)
*/
public function addFormTag ($formName = false, $formId = false) {
// When the form is not yet opened at least form name must be valid
if ((!$this->formOpened) && ($formName === false)) {
// Thrown an exception
throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID);
}
// Close the form is default
$formContent = "";
// Check wether we shall open or close the form
if (!$this->formOpened) {
// Add HTML code
$formContent = sprintf("