summaryrefslogtreecommitdiff
path: root/modules/forge/libraries/Form_Group.php
blob: 0c6dd100547d533b303726e2b9d6ff94a1d735aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
 * FORGE group library.
 *
 * $Id$
 *
 * @package    Forge
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @license    http://kohanaphp.com/license.html
 */
class Form_Group_Core extends Forge {

	protected $data = array
	(
		'type'  => 'group',
		'name'  => '',
		'class' => 'group',
		'label' => '',
		'message' => ''
	);

	// Input method
	public $method;

	public function __construct($name = NULL, $class = 'group')
	{
		$this->data['name'] = $name;
		$this->data['class'] = $class;

		// Set dummy data so we don't get errors
		$this->attr['action'] = '';
		$this->attr['method'] = 'post';
	}

	public function __get($key)
	{
		if ($key == 'type' || $key == 'name')
		{
			return $this->data[$key];
		}
		return parent::__get($key);
	}

	public function __set($key, $val)
	{
		if ($key == 'method')
		{
			$this->attr['method'] = $val;
		}
		$this->$key = $val;
	}

	public function label($val = NULL)
	{
		if ($val === NULL)
		{
			if ($label = $this->data['label'])
			{
				return $this->data['label'];
			}
		}
		else
		{
			$this->data['label'] = ($val === TRUE) ? ucwords(inflector::humanize($this->data['name'])) : $val;
			return $this;
		}
	}

	public function message($val = NULL)
	{
		if ($val === NULL)
		{
			return $this->data['message'];
		}
		else
		{
			$this->data['message'] = $val;
			return $this;
		}
	}

	public function render()
	{
		// No Sir, we don't want any html today thank you
		return;
	}

} // End Form Group