【问题标题】:Change gender dropdown to radio button in magento将性别下拉菜单更改为 magento 中的单选按钮
【发布时间】:2015-09-03 22:13:11
【问题描述】:

今天我开始在 magento 网站上填写注册表。如您所知,默认情况下它具有gender drop down。我需要把它改成checkbox

到目前为止,我去了register.phtml文件,并尝试添加<input type="radio" ...../>选择文件,但这没有用。

有谁知道如何解决这个问题! 请给我一些建议,这样......

【问题讨论】:

    标签: magento


    【解决方案1】:

    不要忘记验证!

    <div class="input-box">
        <?php
            $options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();
            $value = $this->getGender();
            $_last = count($options);
            $_index = 0;
        ?>
        <?php foreach ($options as $option):?>
            <?php if($option['value'] != ''): ?>
                <input id="<?php echo $this->getFieldId('gender')?>-<?php echo $option['value'] ?>"
                       class="radio<?php if ($this->isRequired() && $_index == $_last - 1):?> validate-one-required<?php endif; ?>"
                       type="radio" title="<?php echo $option['label'] ?>"
                       value="<?php echo $option['value'] ?>" name="<?php echo $this->getFieldName('gender')?>"
                       <?php if ($option['value'] == $value) echo ' checked="checked"' ?>>
                <label for="<?php echo $this->getFieldId('gender')?>-<?php echo $option['value'] ?>">
                    <?php echo $option['label'] ?>
                </label>
            <?php endif; ?>
    
            <?php $_index++; ?>
        <?php endforeach;?>
    </div>
    

    【讨论】:

      【解决方案2】:

      Magento 在注册表单上使用小部件。实际上在模板 register.phtml 中你可以看到以下几行:

      
      <?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
      <?php if ($_gender->isEnabled()): ?>
          <li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
      <?php endif ?>
      

      这个特定的小部件可以在template/customer/widget 目录中找到。因此,为了将选择更改为单选按钮,请将其(模板)复制到您的主题并进行修改,例如:

      
      <div class="input-box">
          <label><?php echo $this->__('Gender'); ?></label>
          <?php $options = Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAllOptions();?>
          <?php $value = $this->getGender();?>
          <?php foreach ($options as $option):?>
          <input type="radio" name="<?php echo $this->getFieldName('gender')?>" value="<?php echo $option['value'] ?>"<?php if ($option['value'] == $value) echo ' selected="selected"' ?> /><?php echo $option['label'] ?>
          <br />
          <?php endforeach;?>
      </div>
      

      希望没有打错字。

      【讨论】:

      猜你喜欢
      • 2013-11-24
      • 2017-08-26
      • 2015-08-06
      • 2018-09-16
      • 2014-12-30
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多