概述
这是一个老帖子,但它仍然可以对某人有用:
是的你可以.
以下代码位于:
应用程序/代码/本地/ 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表单所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复