将性别下拉菜单更改为magento中的单选按钮

时间:2012-06-22 14:19:33

标签: magento

今天我开始在magento网站注册表格。如您所知,默认情况下它有gender drop down。我需要将其更改为checkbox

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

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

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

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>

希望没有做任何错字。