|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the MIT license. |
|
18
|
|
|
*/ |
|
19
|
|
|
namespace LearnZF2Barcode\Form; |
|
20
|
|
|
|
|
21
|
|
|
use Zend\Form\Form; |
|
22
|
|
|
use Zend\InputFilter\InputFilterProviderInterface; |
|
23
|
|
|
|
|
24
|
|
|
class BarcodeForm extends Form implements InputFilterProviderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var [] array of barcode object values |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $objectSelectValues; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* construct objectSelectValues value options. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(array $objectSelectValues) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->objectSelectValues = array_combine($objectSelectValues, $objectSelectValues); |
|
37
|
|
|
parent::__construct('barcode-form'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function init() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->add([ |
|
46
|
|
|
'type' => 'Zend\Form\Element\Select', |
|
47
|
|
|
'name' => 'barcode-object-select', |
|
48
|
|
|
'options' => [ |
|
49
|
|
|
'label' => 'Barcode Objects', |
|
50
|
|
|
'value_options' => $this->objectSelectValues, |
|
51
|
|
|
], |
|
52
|
|
|
'attributes' => [ |
|
53
|
|
|
'class' => 'form-control', |
|
54
|
|
|
], |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$this->add([ |
|
58
|
|
|
'type' => 'Zend\Form\Element\Text', |
|
59
|
|
|
'name' => 'barcode-object-text', |
|
60
|
|
|
'options' => [ |
|
61
|
|
|
'value_options' => [], |
|
62
|
|
|
], |
|
63
|
|
|
'attributes' => [ |
|
64
|
|
|
'value' => '123456789', |
|
65
|
|
|
], |
|
66
|
|
|
]); |
|
67
|
|
|
|
|
68
|
|
|
$this->add([ |
|
69
|
|
|
'name' => 'submit', |
|
70
|
|
|
'attributes' => [ |
|
71
|
|
|
'class' => 'form-control', |
|
72
|
|
|
'type' => 'submit', |
|
73
|
|
|
'value' => 'Go', |
|
74
|
|
|
'id' => 'submitbutton', |
|
75
|
|
|
], |
|
76
|
|
|
]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getInputFilterSpecification() |
|
83
|
|
|
{ |
|
84
|
|
|
return [ |
|
85
|
|
|
|
|
86
|
|
|
[ |
|
87
|
|
|
'name' => 'barcode-object-select', |
|
88
|
|
|
'validators' => [ |
|
89
|
|
|
[ |
|
90
|
|
|
'name' => 'InArray', |
|
91
|
|
|
'options' => [ |
|
92
|
|
|
'haystack' => array_keys($this->objectSelectValues), |
|
93
|
|
|
'messages' => [ |
|
94
|
|
|
'notInArray' => 'Please select the object select !', |
|
95
|
|
|
], |
|
96
|
|
|
], |
|
97
|
|
|
], |
|
98
|
|
|
], |
|
99
|
|
|
], |
|
100
|
|
|
|
|
101
|
|
|
[ |
|
102
|
|
|
'name' => 'barcode-object-text', |
|
103
|
|
|
'required' => true, |
|
104
|
|
|
'filters' => [ |
|
105
|
|
|
['name' => 'StripTags'], |
|
106
|
|
|
['name' => 'StringTrim'], |
|
107
|
|
|
], |
|
108
|
|
|
'validators' => [ |
|
109
|
|
|
[ |
|
110
|
|
|
'name' => 'StringLength', |
|
111
|
|
|
'options' => [ |
|
112
|
|
|
'encoding' => 'UTF-8', |
|
113
|
|
|
'min' => 1, |
|
114
|
|
|
], |
|
115
|
|
|
], |
|
116
|
|
|
], |
|
117
|
|
|
], |
|
118
|
|
|
]; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|