Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento-添加按钮[+;添加字段],用于在system.xml中添加/显示新的文本字段_Magento_Magento 1.5 - Fatal编程技术网

Magento-添加按钮[+;添加字段],用于在system.xml中添加/显示新的文本字段

Magento-添加按钮[+;添加字段],用于在system.xml中添加/显示新的文本字段,magento,magento-1.5,Magento,Magento 1.5,我有一个带有可选文本字段的自定义模块(通过system.xml中的标准文本字段选项显示)。我想做的是显示一个必填文本字段,并有一个按钮,上面写着类似于[+addfield]的内容。按下该按钮时,会添加另一个文本字段。我想为最多10个总文本字段(最多)执行此操作。有人能帮我完成这项任务吗,或者给我一个关于如何完成这项任务的好教程 在上午11:30编辑7/10/12 我一直在做这个,到目前为止,我可以让文本字段显示出来。但是我有一些问题 按“保存配置”按钮时,在这些动态创建的文本字段中输入的值实际上

我有一个带有可选文本字段的自定义模块(通过system.xml中的标准文本字段选项显示)。我想做的是显示一个必填文本字段,并有一个按钮,上面写着类似于[+addfield]的内容。按下该按钮时,会添加另一个文本字段。我想为最多10个总文本字段(最多)执行此操作。有人能帮我完成这项任务吗,或者给我一个关于如何完成这项任务的好教程

在上午11:30编辑7/10/12

我一直在做这个,到目前为止,我可以让文本字段显示出来。但是我有一些问题

  • 按“保存配置”按钮时,在这些动态创建的文本字段中输入的值实际上都不会保存
  • 有没有办法限制实际保存多少文本字段
  • 我不确定检索文本字段数据的正确方法。这主要是因为我无法保存值…(如果需要帮助,我将在#1修复后添加另一个更新…)
  • 我的System.xml文件中包含此内容(与此直接相关)

    
    这是一些标签
    这是一些评论。
    文本
    公司名称空间/adminhtml\u文本字段
    adminhtml/system\u config\u backend\u序列化
    50
    1.
    1.
    0
    
    我的自定义Textfields.php(前端_模型)文件内容:

    <?php
    
    class Company_Namespace_Block_Adminhtml_Textfields extends Mage_Adminhtml_Block_System_Config_Form_Field
    {
    protected $_addRowButtonHtml = array();
    protected $_removeRowButtonHtml = array();
    
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
    
        $html = '<div id="code_label_textfields_template" style="display:none">';
        $html .= $this->_getRowTemplateHtml();
        $html .= '</div>';
    
        $html .= '<ul id="code_label_textfields_container">';
    
        if ($this->_getValue('method')) {
            foreach ($this->_getValue('method') as $i=>$f) {
                if ($i) {
                    $html .= $this->_getRowTemplateHtml($i);
                }
            }
        }
    
        $html .= '</ul>';
    
    
        $html .= $this->_getAddRowButtonHtml('code_label_textfields_container', 'code_label_textfields_template', $this->__('Button Label Here'));
    
        return $html;
    }
    
    protected function _getRowTemplateHtml()
    {
        $html = '<li>';
    
        $html .= '<div style="margin:5px 0 10px;">';
        $html .= '<input class="input-text" name="'.$this->getElement()->getName().'" value="'.$this->_getValue('price/'.$i).'" '.$this->_getDisabled().'/> ';
    
        $html .= $this->_getRemoveRowButtonHtml();
        $html .= '</div>';
    
        $html .= '</li>';
    
        return $html;
    }
    
    
    
    protected function _getDisabled()
    {
        return $this->getElement()->getDisabled() ? ' disabled' : '';
    }
    
    protected function _getValue($key)
    {
        return $this->getElement()->getData('value/'.$key);
    }
    
    protected function _getSelected($key, $value)
    {
        return $this->getElement()->getData('value/'.$key)==$value ? 'selected="selected"' : '';
    }
    
    protected function _getAddRowButtonHtml($container, $template, $title='Add')
    {
        if (!isset($this->_addRowButtonHtml[$container])) {
            $this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('add '.$this->_getDisabled())
                    ->setLabel($this->__($title))
                    //$this->__('Add')
                    ->setOnClick("Element.insert($('".$container."'), {bottom: $('".$template."').innerHTML})")
                    ->setDisabled($this->_getDisabled())
                    ->toHtml();
        }
        return $this->_addRowButtonHtml[$container];
    }
    
    protected function _getRemoveRowButtonHtml($selector='li', $title='Remove')
    {
        if (!$this->_removeRowButtonHtml) {
            $this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('delete v-middle '.$this->_getDisabled())
                    ->setLabel($this->__($title))
                    //$this->__('Remove')
                    ->setOnClick("Element.remove($(this).up('".$selector."'))")
                    ->setDisabled($this->_getDisabled())
                    ->toHtml();
        }
        return $this->_removeRowButtonHtml;
    }
    }
    

    有关示例,请参阅和块。这有点复杂,但它是有效的。您可以在Google Checkout中的商户计算设置中看到这一点。

    有关示例,请参阅和块。这有点复杂,但它是有效的。您可以在Google Checkout的商户计算设置中看到这一点。

    这是可行的,但无法限制填充多少字段?我正在处理这个部分,但它似乎没有任何限制…$html.=$this->\u getAddRowButtonHtml('some\u container'、'some\u template'、$this->\uuuuu('some Label');。哦,那么您将如何从文本字段中检索数据呢?它们存储在序列化数组中的core_config_数据中。再次感谢您的持续支持。我添加了更多的细节。在GoogleCheckout模块的Merchant.php中,它有一个getShippingMethods()函数,似乎可以保存??你能详细说明一下吗,因为我在保存值时遇到了问题(它们不保存)。我在上面输入了更多的细节。谢谢这是可行的,但没有办法限制填充多少字段?我正在处理这个部分,但它似乎没有任何限制…$html.=$this->\u getAddRowButtonHtml('some\u container'、'some\u template'、$this->\uuuuu('some Label');。哦,那么您将如何从文本字段中检索数据呢?它们存储在序列化数组中的core_config_数据中。再次感谢您的持续支持。我添加了更多的细节。在GoogleCheckout模块的Merchant.php中,它有一个getShippingMethods()函数,似乎可以保存??你能详细说明一下吗,因为我在保存值时遇到了问题(它们不保存)。我在上面输入了更多的细节。谢谢
    <?php
    
    class Company_Namespace_Block_Adminhtml_Textfields extends Mage_Adminhtml_Block_System_Config_Form_Field
    {
    protected $_addRowButtonHtml = array();
    protected $_removeRowButtonHtml = array();
    
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
    
        $html = '<div id="code_label_textfields_template" style="display:none">';
        $html .= $this->_getRowTemplateHtml();
        $html .= '</div>';
    
        $html .= '<ul id="code_label_textfields_container">';
    
        if ($this->_getValue('method')) {
            foreach ($this->_getValue('method') as $i=>$f) {
                if ($i) {
                    $html .= $this->_getRowTemplateHtml($i);
                }
            }
        }
    
        $html .= '</ul>';
    
    
        $html .= $this->_getAddRowButtonHtml('code_label_textfields_container', 'code_label_textfields_template', $this->__('Button Label Here'));
    
        return $html;
    }
    
    protected function _getRowTemplateHtml()
    {
        $html = '<li>';
    
        $html .= '<div style="margin:5px 0 10px;">';
        $html .= '<input class="input-text" name="'.$this->getElement()->getName().'" value="'.$this->_getValue('price/'.$i).'" '.$this->_getDisabled().'/> ';
    
        $html .= $this->_getRemoveRowButtonHtml();
        $html .= '</div>';
    
        $html .= '</li>';
    
        return $html;
    }
    
    
    
    protected function _getDisabled()
    {
        return $this->getElement()->getDisabled() ? ' disabled' : '';
    }
    
    protected function _getValue($key)
    {
        return $this->getElement()->getData('value/'.$key);
    }
    
    protected function _getSelected($key, $value)
    {
        return $this->getElement()->getData('value/'.$key)==$value ? 'selected="selected"' : '';
    }
    
    protected function _getAddRowButtonHtml($container, $template, $title='Add')
    {
        if (!isset($this->_addRowButtonHtml[$container])) {
            $this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('add '.$this->_getDisabled())
                    ->setLabel($this->__($title))
                    //$this->__('Add')
                    ->setOnClick("Element.insert($('".$container."'), {bottom: $('".$template."').innerHTML})")
                    ->setDisabled($this->_getDisabled())
                    ->toHtml();
        }
        return $this->_addRowButtonHtml[$container];
    }
    
    protected function _getRemoveRowButtonHtml($selector='li', $title='Remove')
    {
        if (!$this->_removeRowButtonHtml) {
            $this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('delete v-middle '.$this->_getDisabled())
                    ->setLabel($this->__($title))
                    //$this->__('Remove')
                    ->setOnClick("Element.remove($(this).up('".$selector."'))")
                    ->setDisabled($this->_getDisabled())
                    ->toHtml();
        }
        return $this->_removeRowButtonHtml;
    }
    }