`
天梯梦
  • 浏览: 13741568 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

Magento: Gird 和 form 区域 Module Development Series – Magento Admin Module

 
阅读更多
In this tutorial, we are going to see all the different form fields we can use in admin forms.

Magento has many different type of field available by default, so lets see the syntax of using each of these fields. This tutorial is in continuation of the previous tutorial so the same classes will be used as in the previous post.


All the code’s written below are written in the class Excellence_Form_Block_Adminhtml_Form_Edit_Tab_Form inside the _prepareForm() function as shown in previous tutorial. All the different type of form fields available in magento are located in folder lib\Varien\Data\Form\Element

 

Text Field

Here is how to add a text field to an admin form, with a list of all the options

$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
$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
$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 Button
$fieldset->addField('submit', 'submit', array(
          'label'     => Mage::helper('form')->__('Submit'),
          'required'  => true,
          'value'  => 'Submit',
          'after_element_html' => '<small>Comments</small>',
          'tabindex' => 1
        ));
 
DropDown
$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
        ));
 

Here is another version of the drop down

$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 Button
$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 Field
$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'  => '123456789',
          'after_element_html' => '<small>Comments</small>',
          'tabindex' => 1
        ));
 
Note
$fieldset->addField('note', 'note', array(
          'text'     => Mage::helper('form')->__('Text Text'),
        ));
 
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' => '<small>Comments</small>',
          'tabindex' => 1
        ));
 
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' => '<small>Comments</small>',
          'tabindex' => 1
        ));
 
Link
$fieldset->addField('link', 'link', array(
          'label'     => Mage::helper('form')->__('Link'),
          'style'   => "",
          'href' => 'www.excellencemagentoblog.com',
          'value'  => 'Magento Blog',
          'after_element_html' => ''
        ));
 
Label
$fieldset->addField('label', 'label', array(
          'value'     => Mage::helper('form')->__('Label Text'),
        ));
 
Image Upload
$fieldset->addField('image', 'image', array(
          'value'     => 'http://www.excellencemagentoblog.com/wp-content/themes/excelltheme/images/logo.png',
        ));
 
File Upload
$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
$fieldset->addField('date', 'date', array(
          'label'     => Mage::helper('form')->__('Date'),
          'after_element_html' => '<small>Comments</small>',
          'tabindex' => 1,
          'image' => $this->getSkinUrl('images/grid-cal.gif'),
          'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
        ));
 
Checkbox
$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
        ));
 

hiden

$fieldset->addField('post_id', 'hidden', array(
'label' => Mage::helper('blog')->__('Post'),
'class' => 'required-entry',
'required' => true,
'name' => 'post_id',
));

 

 

原文/转自: Magento: Module Development Series – Magento Admin Module

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Magento: 后台添加预览按钮 View product in frontend from Magento admin

    这篇博客“Magento:后台添加预览按钮 View product in frontend from Magento admin”主要探讨了如何通过自定义开发来实现这一功能,让管理员能够快速检查商品在网站前台的显示状态。 在Magento中,通常管理员需要...

    Magento: Beginner's Guide ([Packt]出品 Magento新手指南)

    ### Magento新手指南知识点详解 #### 一、Magento简介与特性 **Magento**是一款功能强大的开源电子商务平台,由Varien公司(后被Adobe收购)于2008年首次发布。它以其灵活性、可扩展性和丰富的功能集而闻名,是...

    Magento:适用于Dropday的Magento扩展

    运行以下命令以启用Dropday扩展: php bin/magento module:enable Dropday_OrderAutomation 运行Magento安装程序升级: php bin/magento setup:upgrade 运行Magento依赖项注入编译: php bin/magento setup:di:...

    Create new module “HelloWorld” – in Magento

    &lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"&gt; &lt;module name="HelloWorld" setup_version="1.0.0"/&gt; ``` 接...

    The Definitive Guide to Magento (Apress出品 Magento权威指南)

    本章首先介绍了Magento的历史背景和发展历程,然后详细阐述了Magento的核心概念和技术架构。此外,还探讨了Magento与其他电子商务平台的区别以及其优势所在。 - **第2章:环境搭建与安装** 在这一章节中,作者...

    magento2-module-cmsbanner:magento 2扩展程序,用于向cms页面添加横幅

    将图片上传器添加到Magento后端在后端上传的图像可以在前端int的相应页面中查看易于在任何magento安装中使用安装✓通过作曲家安装在Magento 2根文件夹中运行以下命令: composer require prateekkarki/module-...

    magento2-integration

    Magento:registered:2数据集成借助Datatric Connect扩展程序,可以轻松地将Magento:registered:2商店与Datatrics平台连接起来。安装在开始安装过程之前,我们建议您对webshop文件以及数据库进行备份。 有两种安装...

    magento:Magento的免费PWA和SPA

    Magento通过最佳的电子商务平台和灵活的云解决方案为成千上万的零售商和品牌提供支持,以实现快速创新和发展。 CMS Connect App-通过GraphQL API在Magento CMS和VueFront Web App之间添加连接。它有什么作用? 这是...

    m2_belvg_product-tabs-2.0.0.zip

    5. Flush cache php bin/magento cache:flush,...To activate the module log into the Magento admin panel and navigate to Stores -&gt; Configuration -&gt; BelVG Extensions -&gt; Product Tabs. General settings will...

    magento:Magento片段

    总的来说,Magento是一个功能强大的电子商务平台,其丰富的API和插件生态系统为开发者提供了广阔的空间来实现创新和定制。深入了解和熟练掌握Magento的片段及其相关概念,将有助于你构建高质量的在线商店。

    Magento Development Cookbook

    - **Magento Development Cookbook**:本书是针对Magento开发者的指南书籍,主要聚焦于如何创建自定义主题和模块,为开发者提供了实用的技术指导。 #### 二、开发Magento主题与模块 - **主题开发**:Magento支持...

    module-codemirror:Magento 2的CodeMirror

    代码镜像CodeMirror-是Magento 2模块,... form xmlns : xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi : noNamespaceSchemaLocation = " urn:magento:module:Magento_Ui:etc/ui_configuration.xsd " &gt;

    ansible-magento:ansible置备的magento商店

    ansible-magento要求: -流浪汉-可以指示: 克隆此仓库无所事事在浏览器中导航到magento.dev。MySQL 数据库:magento 用户名:magento 密码:password123 这是基于的工作而进行的一些更改,以简化启动和运行过程...

    docker-magento:Mark Shust的Magento Docker配置

    docker-magento:Mark Shust的Magento Docker配置

    magento2-blog-module-tutorial, 关于如何从头开始创建 magento 2模块的教程,带有测试.zip

    magento2-blog-module-tutorial, 关于如何从头开始创建 magento 2模块的教程,带有测试 2博客模块教程这个模块是 WIP,它将被更新为每个教程我目前正在写。介绍如何从头创建完整功能的Magento 2模块。 即使有测试,...

    magento2-reindex:这是Magento 2的模块。这允许从Magento 2 Admin重新索引数据

    Magento2 ReIndex数据(Wbs_Reindexer)v1.0.0 Magento 2扩展 该扩展程序有助于从admin重新编制数据索引,而无需执行命令行(CLI)。 特征: 便于使用 来自管理员的简单重新... 有关Magento 2的更多文章和教程,请访

    magento:Gimmie Magento 模块

    为 Magento 添加 Gimmie 奖励,让用户在购买和推荐朋友时获得积分并获得真正的奖励。 要安装此插件,我们提供。 建造 克隆此插件所需的所有子模块(gimmie php 项目) $git submodule init && git submodule ...

    magento安装错误解决

    ### Magento安装错误解决方案 在初次尝试安装Magento时,可能会遇到一系列技术问题,这些问题往往与服务器配置、PHP扩展、权限设置等密切相关。以下是一些常见问题及其解决方案。 #### 1. PHP Extension "curl" 和...

    magento:Magento 2

    Magento 2 是一款开源的电子商务平台,用于构建和管理在线商店。它由Adobe公司拥有,是Magento 1的升级版本,提供了许多改进的功能和性能优化。Magento 2 的设计目标是提供一个高度可定制、功能丰富的电商解决方案,...

Global site tag (gtag.js) - Google Analytics