我是靠谱客的博主 生动百合,最近开发中收集的这篇文章主要介绍php自定义表单程序,php – 将自定义表单元素添加到Adminhtml表单,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这是一个老帖子,但它仍然可以对某人有用:

是的你可以.

以下代码位于:

应用程序/代码/本地/ MyCompany的/ MyModule的/座/ MyForm.php

class MyCompany_MyModule_Block_MyForm extends Mage_Adminhtml_Block_Widget_Form

{

protected function _prepareForm()

{

$form = new Varien_Data_Form(array(

'id' => 'edit_form',

'action' => $this->getUrl('*/*/save'),

'method' => 'post'

));

$fieldset = $form->addFieldset('my_fieldset', array('legend' => 'Your fieldset title')));

//Here is what is interesting us

//We add a new type, our type, to the fieldset

//We call it extended_label

$fieldset->addType('extended_label','MyCompany_MyModule_Lib_Varien_Data_Form_Element_ExtendedLabel');

$fieldset->addField('mycustom_element', 'extended_label', array(

'label' => 'My Custom Element Label',

'name' => 'mycustom_element',

'required' => false,

'value' => $this->getLastEventLabel($lastEvent),

'bold' => true,

'label_style' => 'font-weight: bold;color:red;',

));

}

}

这是您的自定义元素的代码,它位于app / code / local / MyCompany / MyModule / Lib / Varien / Data / Form / Element / ExtendedLabel.php中:

class MyCompany_MyModule_Lib_Varien_Data_Form_Element_ExtendedLabel extends Varien_Data_Form_Element_Abstract

{

public function __construct($attributes=array())

{

parent::__construct($attributes);

$this->setType('label');

}

public function getElementHtml()

{

$html = $this->getBold() ? '' : '';

$html.= $this->getEscapedValue();

$html.= $this->getBold() ? '' : '';

$html.= $this->getAfterElementHtml();

return $html;

}

public function getLabelHtml($idSuffix = ''){

if (!is_null($this->getLabel())) {

$html = ''.$this->getLabel()

. ( $this->getRequired() ? ' *' : '' ).''."n";

}

else {

$html = '';

}

return $html;

}

}

最后

以上就是生动百合为你收集整理的php自定义表单程序,php – 将自定义表单元素添加到Adminhtml表单的全部内容,希望文章能够帮你解决php自定义表单程序,php – 将自定义表单元素添加到Adminhtml表单所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部