在这一章节,我们将会看到在后台表单中如何添加不同种类的 文本框 或 HTML 标签
Magento 中自身默认已经封装好许多不同种类的文本框 或 HTML 标签,现在就让我们来看一下每一个的具体使用方法,同样这次的旅程也是延续上几个章节的,这些方法也是对上次已讲过的的类的扩展
接下去你所看见的代码是在写在这个 Excellence_Employee_Block_Adminhtml_Form_Edit_Tab_Form 类中的 _prepareForm() 方法当中, 回顾该方法,如果你有兴趣,你可以查看 lib\Varien\Data\Form\Element 这个文件夹,你会发现它包含所有不同种类的 文本框 或 HTML 标签
Text 类型
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$fieldset
->
addField
(
'title'
,
'text'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Title3'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
"alert('on click');"
,
'onchange'
=
>
"alert('on change');"
,
'style'
=
>
"border:10px"
,
'value'
=
>
'hello !!'
,
'disabled'
=
>
false
,
'readonly'
=
>
true
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Time 类型
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$fieldset
->
addField
(
'time'
,
'time'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Time'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'12-04-15'
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
TextArea 类型
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$fieldset
->
addField
(
'textarea'
,
'textarea'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'TextArea'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'<b></b>'
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Submit 按钮
1
2
3
4
5
6
7
|
$fieldset
->
addField
(
'submit'
,
'submit'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Submit'
)
,
'required'
=
>
true
,
'value'
=
>
'Submit'
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
DropDown 下拉框
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
|
$fieldset
->
addField
(
'select'
,
'select'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Select'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'1'
,
'values'
=
>
array
(
'-1'
=
>
'Please Select..'
,
'1'
=
>
'Option1'
,
'2'
=
>
'Option2'
,
'3'
=
>
'Option3'
)
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
$fieldset
->
addField
(
'select2'
,
'select'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Select Type2'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'4'
,
'values'
=
>
array
(
'-1'
=
>
'Please Select..'
,
'1'
=
>
array
(
'value'
=
>
array
(
array
(
'value'
=
>
'2'
,
'label'
=
>
'Option2'
)
,
array
(
'value'
=
>
'3'
,
'label'
=
>
'Option3'
)
)
,
'label'
=
>
'Size'
)
,
'2'
=
>
array
(
'value'
=
>
array
(
array
(
'value'
=
>
'4'
,
'label'
=
>
'Option4'
)
,
array
(
'value'
=
>
'5'
,
'label'
=
>
'Option5'
)
)
,
'label'
=
>
'Color'
)
,
)
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Radio 类型
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
|
$fieldset
->
addField
(
'radio'
,
'radio'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Radio'
)
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'1'
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
$fieldset
->
addField
(
'radio2'
,
'radios'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Radios'
)
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'2'
,
'values'
=
>
array
(
array
(
'value'
=
>
'1'
,
'label'
=
>
'Radio1'
)
,
array
(
'value'
=
>
'2'
,
'label'
=
>
'Radio2'
)
,
array
(
'value'
=
>
'3'
,
'label'
=
>
'Radio3'
)
,
)
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Password 类型
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
|
$fieldset
->
addField
(
'password'
,
'password'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Password'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'style'
=
>
""
,
'value'
=
>
'hello !!'
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
$fieldset
->
addField
(
'obscure'
,
'obscure'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Obscure'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'obscure'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'style'
=
>
""
,
'value'
=
>
'420560687'
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Note 类型
1
2
3
|
$fieldset
->
addField
(
'note'
,
'note'
,
array
(
'text'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Text Text'
)
,
)
)
;
|
Multiselect 类型
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
|
$fieldset
->
addField
(
'multiselect2'
,
'multiselect'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Select Type2'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
"return false;"
,
'onchange'
=
>
"return false;"
,
'value'
=
>
'4'
,
'values'
=
>
array
(
'-1'
=
>
array
(
'label'
=
>
'Please Select..'
,
'value'
=
>
'-1'
)
,
'1'
=
>
array
(
'value'
=
>
array
(
array
(
'value'
=
>
'2'
,
'label'
=
>
'Option2'
)
,
array
(
'value'
=
>
'3'
,
'label'
=
>
'Option3'
)
)
,
'label'
=
>
'Size'
)
,
'2'
=
>
array
(
'value'
=
>
array
(
array
(
'value'
=
>
'4'
,
'label'
=
>
'Option4'
)
,
array
(
'value'
=
>
'5'
,
'label'
=
>
'Option5'
)
)
,
'label'
=
>
'Color'
)
,
)
,
'disabled'
=
>
false
,
'readonly'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Multiline 类型
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$fieldset
->
addField
(
'multiline'
,
'multiline'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Multi Line'
)
,
'class'
=
>
'required-entry'
,
'required'
=
>
true
,
'name'
=
>
'title'
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'style'
=
>
"border:10px"
,
'value'
=
>
'hello !!'
,
'disabled'
=
>
false
,
'readonly'
=
>
true
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Link 类型
1
2
3
4
5
6
7
|
$fieldset
->
addField
(
'link'
,
'link'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Link'
)
,
'style'
=
>
""
,
'href'
=
>
'www.sunzhenghua.com'
,
'value'
=
>
'Magento Blog'
,
'after_element_html'
=
>
''
)
)
;
|
Label 类型
1
2
3
|
$fieldset
->
addField
(
'label'
,
'label'
,
array
(
'value'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Label Text'
)
,
)
)
;
|
Image Upload 类型
1
2
3
|
$fieldset
->
addField
(
'image'
,
'image'
,
array
(
'value'
=
>
'http://www.sunzhenghua.com/shawn.jpg'
,
)
)
;
|
File Upload 类型
1
2
3
4
5
6
7
8
|
$fieldset
->
addField
(
'file'
,
'file'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Upload'
)
,
'value'
=
>
'Uplaod'
,
'disabled'
=
>
false
,
'readonly'
=
>
true
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
Date 类型
1
2
3
4
5
6
7
8
9
|
$fieldset
->
addField
(
'date'
,
'date'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Date'
)
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
,
'image'
=
>
$this
->
getSkinUrl
(
'images/good_luck.gif'
)
,
'format'
=
>
Mage::
app
(
)
->
getLocale
(
)
->
getDateFormat
(
Mage_Core_Model_Locale::
FORMAT_TYPE_SHORT
)
)
)
;
|
Checkbox 类型
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
|
$fieldset
->
addField
(
'checkbox'
,
'checkbox'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Checkbox'
)
,
'name'
=
>
'Checkbox'
,
'checked'
=
>
false
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'1'
,
'disabled'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
$fieldset
->
addField
(
'checkboxes'
,
'checkboxes'
,
array
(
'label'
=
>
Mage::
helper
(
'form'
)
->
__
(
'Checkboxs'
)
,
'name'
=
>
'Checkbox'
,
'values'
=
>
array
(
array
(
'value'
=
>
'1'
,
'label'
=
>
'Checkbox1'
)
,
array
(
'value'
=
>
'2'
,
'label'
=
>
'Checkbox2'
)
,
array
(
'value'
=
>
'3'
,
'label'
=
>
'Checkbox3'
)
,
)
,
'onclick'
=
>
""
,
'onchange'
=
>
""
,
'value'
=
>
'1'
,
'disabled'
=
>
false
,
'after_element_html'
=
>
'<small>Comments</small>'
,
'tabindex'
=
>
1
)
)
;
|
下一章节我们将会深入了解一些关于后台表单的操作
source: http://www.sunzhenghua.com/magento-admin-module-development-part4-grid-forms-tabs-addField