如何在magento中的自定义addField表单函数中添加div类?

时间:2015-09-25 06:29:56

标签: html magento

我创建了一个带有一些字段的自定义模块。我使用Varien_Data_Form来创建带字段的表单。我添加了无线电按钮,我只想在这些单选按钮之间添加一个<div>。我不知道那样做。

表单的单选按钮代码:

   $productField=$fieldset->addField('radio2', 'radios', array(
      'name'      => 'house_building',
      'value'  => '1',
      'class'  => 'house_building',
      'values' => array(
                        array('value'=>'1','label'=>'House','id'=>'house'),
                        array('value'=>'2','label'=>'Building','id'=>'house'),
                   ),
    ));

我已在视图页面中使用以下方式打印此表单:

<?php echo $this->getChildHtml("suggestions_edit_form") ?>      

我有以下格式的2个单选按钮:

    <div class="value">
   <input name="house_building" class="house_building" value="1" id="radio21" checked="checked" type="radio"><label class="inline" for="radio21">House</label>
  <input name="house_building" class="house_building" value="2" id="radio22" type="radio"><label class="inline" for="radio22">Building</label>     
      </div>    

现在我想要使用额外的div标记进行以下格式更改:

    <div class="value">
    <div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <input type="radio" checked="checked" id="radio21" value="1" class="house_building validation-passed" name="house_building">
    <label for="radio21" class="inline">House</label>
    </div>
    <div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <input type="radio" id="radio22" value="2" class="house_building validation-passed" name="house_building">
    <label for="radio22" class="inline">Building</label>          
    </div>
    </div>

我不知道怎么做?

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我已经为这个特定的单选按钮添加了一个助手:

我的帮助文件:

   class NextBits_Marketplace_Block_Form_Helper_Type extends Varien_Data_Form_Element_Text
        {
            /**
             * Validation classes for weight field which corresponds to DECIMAL(12,4) SQL type
             *
             * @param array $attributes
             */
            public function __construct(array $attributes = array())
            {
                parent::__construct($attributes);        
            }   
            public function getElementHtml()
            {                       
                $html = '<div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">';
                $html .="<input type=radio checked=checked id=radio21 value=1 class=house_building validation-passed name=house_building>
                <label for=radio21 class=inline>House</label></div>";
                $html .='<div class="field-container col-xs-12 col-sm-12 col-md-12 col-lg-12">';
                $html .="<input type=radio id=radio22 value=2 class=house_building validation-passed name=house_building>
                <label for=radio22 class=inline>Building</label>";
                $html .= '</div>';
                $html .= $this->getAfterElementHtml();
                return $html;
            }
        }

我刚刚在我的Varien_Data_Form addfield中调用了这个帮助器:

    $fieldset->addType('type', 'NextBits_Marketplace_Block_Form_Helper_Type');

    $fieldset->addField('type', 'type', array(
        'name'      => 'house_building',
        'value'  => '1',
        'class'  => 'house_building',
        'container_class' => 'col-xs-12 col-sm-12 col-md-12 col-lg-12 customer-profile-radio'
    ));

现在我得到了带有div标签的输出。