开发Magento后台的时候经常用到表单(Varien_Data_Form),下面是所有表单元素的添加方法:
非必填 注释掉
- 'class' => 'required-entry',
- 'required' => true,
1.input type='text'
- $fieldset->addField('title', 'text', array(
- 'label' => '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' => 'Comments',
- 'tabindex' => 1
- ));
2.Time时间类型
- $fieldset->addField('time', 'time', array(
- 'label' => 'Time',
- 'class' => 'required-entry',
- 'required' => true,
- 'name' => 'title',
- 'onclick' => '',
- 'onchange' => '',
- 'value' => '12,04,15',
- 'disabled' => false,
- 'readonly' => false,
- 'after_element_html' => '<script src="js/extjs/ext-tree.js" type="text/javascript">',
- 'tabindex' => 1
- ));
3.textarea
- $fieldset->addField('textarea', 'textarea', array(
- 'label' => '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
- ));
4.input type='submit'
- $fieldset->addField('submit', 'submit', array(
- 'label' => 'Submit',
- 'required' => true,
- 'value' => 'Submit',
- 'after_element_html' => '',
- 'tabindex' => 1
- ));
5.select option
- $fieldset->addField('select', 'select', array(
- 'label' => '页面样式',
- 'class' => 'required-entry',
- 'required' => true,
- 'name' => 'skin',
- 'onclick' => '',
- 'onchange' => '',
- 'value' => '1',
- 'values' => array('-1' => '请选择', '1' => '红', '2' => '蓝'),
- 'disabled' => false,
- 'readonly' => false,
- 'after_element_html' => '',
- 'tabindex' => 1
- ));
6.带optgroup的select
- $fieldset->addField('select2', 'select', array(
- 'label' => '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' => '',
- 'tabindex' => 1
- ));
7.单选框input type='radio'
- $fieldset->addField('radio', 'radio', array(
- 'label' => 'Radio',
- 'name' => 'title',
- 'onclick' => '',
- 'onchange' => '',
- 'value' => '1',
- 'disabled' => false,
- 'readonly' => false,
- 'after_element_html' => '',
- 'tabindex' => 1
- ));
- $fieldset->addField('radio2', 'radios', array(
- 'label' => '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' => '',
- 'tabindex' => 1
- ));
8.Password元素 input type='password
- $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' => '',
- 'tabindex' => 1
- ));
- $fieldset->addField('obscure', 'obscure', array(
- 'label' => Mage::helper('form')->__('Obscure'),
- 'class' => 'required-entry',
- 'required' => true,
- 'name' => 'obscure',
- 'onclick' => '',
- 'onchange' => '',
- 'style' => '',
- 'value' => '123456789',
- 'after_element_html' => '',
- 'tabindex' => 1
- ));
9.Note
- $fieldset->addField('note', 'note', array(
- 'text' => Mage::helper('form')->__('Text Text'),
- ));
10.Multiselect复选框
- $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' => ' ',
- 'tabindex' => 1
- ));
11.Multiline
- $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' => '',
- 'tabindex' => 1
- ));
12.Link 链接
- $fieldset->addField('link', 'link', array(
- 'label' => Mage::helper('form')->__('Link'),
- 'style' => '',
- 'href' => 'www.excellencemagentoblog.com',
- 'value' => 'Magento Blog',
- 'after_element_html' => ''
- ));
13.普通Label
- $fieldset->addField('label', 'label', array(
- 'value' => Mage::helper('form')->__('Label Text'),
- ));
14.Image Upload图片上传
- $fieldset->addField('image', 'image', array(
- 'value' => 'http://www.test.com//images/logo.png',
- ));
15.File Upload文件上传
- $fieldset->addField('file', 'file', array(
- 'label' => Mage::helper('form')->__('Upload'),
- 'value' => 'Uplaod',
- 'disabled' => false,
- 'readonly' => true,
- 'after_element_html' => '',
- 'tabindex' => 1
- ));
16.日期Date
- $fieldset->addField('date_expires', 'date', array(
- 'name' => 'date_expires',
- 'label' => '过期时间',
- 'title' => '过期时间',
- 'image' => $this->getSkinUrl('images/grid-cal.gif'),
- 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
- 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)
- ));
17.Checkbox
- $fieldset->addField('checkbox', 'checkbox', array(
- 'label' => Mage::helper('form')->__('Checkbox'),
- 'name' => 'Checkbox',
- 'checked' => false,
- 'onclick' => '',
- 'onchange' => '',
- 'value' => '1',
- 'disabled' => false,
- 'after_element_html' => '',
- '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' => '',
- 'tabindex' => 1
- ));
添加文本编辑器 js部分
- protected function _prepareLayout() {
- parent::_prepareLayout();
- if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
- $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
- }
- }
Form
- $fieldset->addField('content', 'editor', array(
- 'name' => 'content',
- 'label' => 'Content',
- 'title' => 'Content',
- 'style' => 'height:15em',
- 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
- 'wysiwyg' => true,
- 'required' => false,
- ));
时间: 2024-10-30 11:45:53