blob: ac810299b537835136908928e32e95ad3c4e4085 (
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
|
<?php
/**
* FORGE dropdown input library.
*
* $Id$
*
* @package Forge
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Form_Dropdown_Core extends Form_Input {
protected $data = array
(
'name' => '',
'class' => 'dropdown',
);
protected $protect = array('type');
public function __get($key)
{
if ($key == 'value')
{
return $this->selected;
}
return parent::__get($key);
}
public function html_element()
{
// Import base data
$base_data = $this->data;
unset($base_data['label']);
// Get the options and default selection
$options = arr::remove('options', $base_data);
$selected = arr::remove('selected', $base_data);
return form::dropdown($base_data, $options, $selected);
}
protected function load_value()
{
if (is_bool($this->valid))
return;
$this->data['selected'] = $this->input_value($this->name);
}
public function validate()
{
// Validation has already run
if (is_bool($this->is_valid))
return $this->is_valid;
if ($this->input_value() == FALSE)
{
// No data to validate
return $this->is_valid = FALSE;
}
// Load the submitted value
$this->load_value();
if ( ! array_key_exists($this->value, $this->data['options']))
{
// Value does not exist in the options
return $this->is_valid = FALSE;
}
return parent::validate();
}
} // End Form Dropdown
|