1: <?php
2:
3: /**
4: * This file contains the cHTMLForm class.
5: *
6: * @package Core
7: * @subpackage GUI_HTML
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: * @var string
27: */
28: protected $_name;
29:
30: /**
31: * @var string
32: */
33: protected $_action;
34:
35: /**
36: * @var string
37: */
38: protected $_method;
39:
40: /**
41: * @var array
42: */
43: protected $_vars;
44:
45: /**
46: * Constructor to create an instance of this class.
47: *
48: * Creates an HTML form element.
49: *
50: * @param string $name [optional]
51: * the name of the form
52: * @param string $action [optional]
53: * the action which should be performed when this form is submitted
54: * @param string $method [optional]
55: * the method to use - post or get
56: * @param string $class [optional]
57: * the class of this element
58: */
59: public function __construct($name = '', $action = 'main.php', $method = 'post', $class = '') {
60: parent::__construct('', $class);
61: $this->_tag = 'form';
62: $this->_name = $name;
63: $this->_action = $action;
64: $this->_method = $method;
65: }
66:
67: /**
68: * Sets the given var.
69: *
70: * @param string $var
71: * @param string $value
72: * @return cHTMLForm
73: * $this for chaining
74: */
75: public function setVar($var, $value) {
76: $this->_vars[$var] = $value;
77:
78: return $this;
79: }
80:
81: /**
82: * Renders the form element
83: *
84: * @return string
85: * Rendered HTML
86: */
87: public function toHtml() {
88: $out = '';
89: if (is_array($this->_vars)) {
90: foreach ($this->_vars as $var => $value) {
91: $f = new cHTMLHiddenField($var, $value);
92: $out .= $f->render();
93: }
94: }
95: if ($this->getAttribute('name') == '') {
96: $this->setAttribute('name', $this->_name);
97: }
98: if ($this->getAttribute('method') == '') {
99: $this->setAttribute('method', $this->_method);
100: }
101: if ($this->getAttribute('action') == '') {
102: $this->setAttribute('action', $this->_action);
103: }
104:
105: $attributes = $this->getAttributes(true);
106:
107: return $this->fillSkeleton($attributes) . $out . $this->_content . $this->fillCloseSkeleton();
108: }
109:
110: }
111: