1: <?php
2: /**
3: * This file contains the cHTMLForm class.
4: *
5: * @package Core
6: * @subpackage GUI_HTML
7: * @version SVN Revision $Rev:$
8: *
9: * @author Simon Sprankel
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * cHTMLForm class represents a form.
20: *
21: * @package Core
22: * @subpackage GUI_HTML
23: */
24: class cHTMLForm extends cHTMLContentElement {
25:
26: protected $_name;
27:
28: protected $_action;
29:
30: protected $_method;
31:
32: /**
33: * Creates an HTML form element.
34: *
35: * @param string $name the name of the form
36: * @param string $action the action which should be performed when this form
37: * is submitted
38: * @param string $method the method to use - post or get
39: * @param string $class the class of this element
40: */
41: public function __construct($name = '', $action = 'main.php', $method = 'post', $class = '') {
42: parent::__construct('', $class);
43: $this->_tag = 'form';
44: $this->_name = $name;
45: $this->_action = $action;
46: $this->_method = $method;
47: }
48:
49: /**
50: * Sets the given var.
51: *
52: * @param string $var
53: * @param string $value
54: * @return cHTMLForm $this
55: */
56: public function setVar($var, $value) {
57: $this->_vars[$var] = $value;
58:
59: return $this;
60: }
61:
62: /**
63: * Renders the form element
64: *
65: * @return string Rendered HTML
66: */
67: public function toHTML() {
68: $out = '';
69: if (is_array($this->_vars)) {
70: foreach ($this->_vars as $var => $value) {
71: $f = new cHTMLHiddenField($var, $value);
72: $out .= $f->render();
73: }
74: }
75: if ($this->getAttribute('name') == '') {
76: $this->setAttribute('name', $this->_name);
77: }
78: if ($this->getAttribute('method') == '') {
79: $this->setAttribute('method', $this->_method);
80: }
81: if ($this->getAttribute('action') == '') {
82: $this->setAttribute('action', $this->_action);
83: }
84:
85: $attributes = $this->getAttributes(true);
86:
87: return $this->fillSkeleton($attributes) . $out . $this->_content . $this->fillCloseSkeleton();
88: }
89:
90: }
91: