array('form-horizontal' => true), 'method' => 'post', // Empty is interpreted by all browsers to submit to the current URI 'action' => '', ); protected $_sections = array(); protected $_global = array(); public function __construct($submit = null) { if (!isset($submit)) $submit = 'Save'; if (gettype($submit) == 'string') $submit = new Form_Button( 'save', $submit ); if (false !== $submit) $this->addGlobal($submit); } public function add(Form_Section $section) { array_push($this->_sections, $section); $section->_setParent($this); return $section; } public function setAction($url) { $this->_attributes['action'] = $url; return $this; } public function addGlobal(Form_Input $input) { array_push($this->_global, $input); return $input; } public function setMultipartEncoding() { $this->_attributes['enctype'] = 'multipart/form-data'; return $this; } protected function _setParent() { throw new Exception('Form does not have a parent'); } public function __toString() { $element = parent::__toString(); $html = implode('', $this->_sections); $buttons = ''; foreach ($this->_global as $global) { if ($global instanceof Form_Button) $buttons .= $global; else $html .= $global; } if (!empty($buttons)) { $group = new Form_Element; $group->addClass('col-sm-'. Form::MAX_INPUT_WIDTH, 'col-sm-offset-'. Form::LABEL_WIDTH); $html .= $group . $buttons .''; } return << EOT; } }