-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form.php
89 lines (78 loc) · 2.78 KB
/
Form.php
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
/**
*
* @author Wilson Ramiro Champi Tacuri
*/
class ZendR_Form extends Zend_Form
{
private $_hashName = '';
public function __construct($options = null)
{
parent::__construct($options);
$aceptar = $this->createElement('submit', Zend_Registry::get('Zend_Translate')->_('accept'))
->setLabel(Zend_Registry::get('Zend_Translate')->_('Accept'))
->setDecorators(ZendR_Decorators::factory('buttomLeft'))
->setAttrib('class', 'btnAction');
$this->addElement($aceptar);
$this->addDisplayGroup(
array(Zend_Registry::get('Zend_Translate')->_('accept')),
'gButtons',
array(
'decorators' => ZendR_Decorators::factory('groupFieldsButton')
)
);
if ($this->getName() == '') {
$hash = new ZendR_Form_Element_Hash();
} else {
$hash = new ZendR_Form_Element_Hash($this->getName() . '_csrf_token');
}
$hash->setTimeout(864000);
$hash->setDecorators(ZendR_Decorators::factory('field'));
$this->addElement($hash);
$this->_hashName = $hash->getName();
foreach ($this->getElements() as $element) {
$htmlTag = $element->getDecorator('HtmlTag');
if ($htmlTag) {
$element->getDecorator('HtmlTag')->setOption('id', $element->getName() . '-element');
}
}
$this->getDecorator('HtmlTag')->clearOptions();
}
public function cleanDecorators() {
foreach ($this->getElements() as $element) {
if ($element instanceof Zend_Form_Element_File) {
$element->setDecorators(ZendR_Decorators::factory('fieldFileClean'));
} else {
$element->setDecorators(ZendR_Decorators::factory('fieldClean'));
}
}
}
public function getElementHash()
{
return $this->getElement($this->_hashName);
}
public function removeElementHash()
{
$this->removeElement($this->_hashName);
}
public function removeElements($elements = null, $excepto = null)
{
if (!is_array($excepto)) {
$excepto = array();
}
if ($elements == null) {
foreach ($this->getElements() as $element) {
if (!in_array($element->getName(), $excepto)) {
$this->removeElement($element->getName());
}
}
} else {
if (is_array($elements)) {
$elements = array_diff($elements, $excepto);
foreach ($elements as $nameElement) {
$this->removeElement($nameElement);
}
}
}
}
}