简体   繁体   中英

Need a button for catalog input type on add attribute page in magento

i created a text field attribute for gift coupon.need a button named "generate" near to it, used to populate the text field with a unique coupon code on the click of that button. searched a lot but nothing got.

updated my code on

app/design/adminhtml/default/default/template/catalog/form/renderer/fieldset/element.phtml

<?php
/**
 * @see Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element
 */
?>
<?php $_element = $this->getElement() ?>
<?php $this->checkFieldDisable() ?>
<?php
    $elementToggleCode = $_element->getToggleCode() ? $_element->getToggleCode()
        : 'toggleValueElements(this, this.parentNode.parentNode)';
?>

<?php if ($_element->getType()=='hidden'): ?>
<tr>
    <td class="hidden" colspan="100"><?php echo trim($_element->getElementHtml()) ?></td>
</tr>
<?php else: ?>
<tr>
    <td class="label"><?php echo trim($this->getElementLabelHtml()) ?></td>
    <td class="value">
        <?php echo trim($this->getElementHtml()) ?>
        <?php if ($_element->getNote()) : ?>
            <p class="note"><?php echo $_element->getNote() ?></p>
        <?php endif; ?>
    </td>
    <td class="scope-label"><span class="nobr"><?php echo $this->getScopeLabel() ?></span></td>
    <?php if ($this->canDisplayUseDefault()): ?>
    <td class="value use-default">
        <input <?php if($_element->getReadonly()):?> disabled="disabled"<?php endif; ?> type="checkbox" name="use_default[]" id="<?php echo $_element->getHtmlId() ?>_default"<?php if ($this->usedDefault()): ?> checked="checked"<?php endif; ?> onclick="<?php echo $elementToggleCode; ?>" value="<?php echo $this->getAttributeCode() ?>"/>
        <label for="<?php echo $_element->getHtmlId() ?>_default" class="normal"><?php echo $this->__('Use Default Value') ?></label>

    </td>
    <?php endif; ?>
</tr>
<?php endif; ?>
**<?php
if($_element->getId()=='giftcoupen'){
  //modify here to have your button
?>
<input type="submit" name="gen" value="Generate" />
<?php
}
?>**  

Then i get a generate button after this .but while clicking on it goes to submit action. i don't have the idea how to make it work to generate the coupon code .


我的页面的屏幕截图

As far as I know, you can achieve this by modifying the following template file

app/design/adminhtml/default/default/template/catalog/form/renderer/fieldset/element.phtml

if($_element->getId()=='your_attribute_code'){
  //modify here to have your button
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM