0

I have a custom module for manage devices and import devices. I have a list of devices with Title, Description etc.. Now, I want to add a dropdown option for item assign to a category "Tab & Smartphone" from admin.

My file is here app/design/adminhtml/default/default/template/widget/form/element.phtml

<?php switch ($element->getType()){
    case 'fieldset': ?>

    <h3><?php echo $element->getLegend() ?></h3>
    <fieldset>
        <legend><?php echo $element->getLegend() ?></legend>
        <?php foreach ($element->getElements() as $_element): ?>
            <?php echo $formBlock->drawElement($_element) ?>
        <?php endforeach; ?>
    </fieldset>
      <?php break;
    case 'column': ?>
      <?php break;
    case 'hidden': ?>
    <input type="<?php echo $element->getType() ?>" name="<?php echo $element->getName() ?>" id="<?php echo $element->getHtmlId() ?>" value="<?php echo $element->getValue() ?>">
      <?php break;
    case 'select': ?>
    <span class="form_row">
        <?php if($element->getLabel()): ?><label for="<?php echo $element->getHtmlId() ?>"><?php echo $element->getLabel() ?>:</label><?php endif; ?>
        <select name="<?php echo $element->getName() ?>" id="<?php echo $element->getHtmlId() ?>" class="select<?php echo $element->getClass() ?>" title="<?php echo $element->getTitle() ?>">
        <?php foreach ($element->getValues() as $_value): ?>
            <option <?php echo $_value->serialize() ?><?php if($_value->getValue() == $element->getValue()): ?> selected="selected"<?php endif; ?>><?php echo $_value->getLabel() ?></option>
        <?php endforeach; ?>
        </select>
    </span>
      <?php break;
    case 'text':
    case 'button':
    case 'password': ?>
    <span class="form_row">
        <?php if($element->getLabel()): ?><label for="<?php echo $element->getHtmlId() ?>"><?php echo $element->getLabel() ?>:</label><?php endif; ?>
        <input type="<?php echo $element->getType() ?>" name="<?php echo $element->getName() ?>" id="<?php echo $element->getHtmlId() ?>" value="<?php echo $element->getValue() ?>" class="input-text <?php echo $element->getClass() ?>" title="<?php echo $element->getTitle() ?>" <?php echo ( $element->getOnClick() ? 'onClick="'.$element->getOnClick().'"' : '' ) ?>/>
    </span>
      <?php break;
    case 'radio': ?>
    <span class="form_row">
        <?php if($element->getLabel()): ?><label for="<?php echo $element->getHtmlId() ?>"><?php echo $element->getLabel() ?>:</label><?php endif; ?>
        <input type="<?php echo $element->getType() ?>" name="<?php echo $element->getName() ?>" id="<?php echo $element->getHtmlId() ?>" value="<?php echo $element->getValue() ?>" class="input-text <?php echo $element->getClass() ?>" title="<?php echo $element->getTitle() ?>"/>
    </span>
      <?php break;
    case 'hidden': ?>
        <input type="<?php echo $element->getType() ?>" name="<?php echo $element->getName() ?>" id="<?php echo $element->getHtmlId() ?>" value="<?php echo $element->getValue() ?>">
      <?php break;
    case 'radios': ?>
    <span class="form_row">
        <label for="<?php echo $element->getHtmlId() ?>"><?php echo $element->getLabel() ?>:</label>
    <?php foreach($element->getRadios() as $_radio): ?>
    <input type="radio" name="<?php echo $_radio->getName() ?>" id="<?php echo $_radio->getHtmlId() ?>" value="<?php echo $_radio->getValue() ?>" class="input-radio <?php echo $_radio->getClass() ?>" title="<?php echo $_radio->getTitle() ?>" <?php echo ( $_radio->getValue() == $element->getChecked() ) ? 'checked="true"' : '' ?> >&nbsp;<?php echo $_radio->getLabel() ?>
    <?php endforeach; ?>
    </span>
      <?php break;
    case 'wysiwyg': ?>
    <span class="form_row">
      <label for="<?php echo $element->getHtmlId() ?>"><?php echo $element->getLabel() ?>:</label>
        <script type="text/javascript" src="<?php echo Mage::getBaseUrl('js') ?>tiny_mce/tiny_mce.js"></script>
        <script type="text/javascript">
        //<![CDATA[
        tinyMCE.init({
            mode : "exact",
            theme : "advanced",
            elements : "<?php echo $element->getName(); ?>",
            plugins : "inlinepopups,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
            theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
            theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,|,visualchars,nonbreaking",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_path_location : "bottom",
            extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
            theme_advanced_resize_horizontal : 'true',
            theme_advanced_resizing : 'true',
            apply_source_formatting : 'true',
            convert_urls : 'false',
            force_br_newlines : 'true',
            doctype : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'

        });
        //]]>
        </script>
      <textarea name="<?php echo $element->getName() ?>" title="<?php echo $element->getTitle() ?>" id="<?php echo $element->getHtmlId() ?>" class="textarea <?php echo $element->getClass() ?>" cols="80" rows="20"><?php echo $element->getValue(); ?></textarea>
    </span>
      <?php break;
        case 'textarea': ?>
            <span class="form_row">
                    <label for="<?php echo $element->getHtmlId() ?>"><?php echo $element->getLabel() ?>:</label>
                    <textarea name="<?php echo $element->getName() ?>" title="<?php echo $element->getTitle() ?>" id="<?php echo $element->getHtmlId() ?>" class="textarea <?php echo $element->getClass() ?>" cols="15" rows="2"><?php echo $element->getValue(); ?></textarea>
            </span>
      <?php break;
    case 'editor': ?>
      <?php break;
    case 'file': ?>
      <?php break;
    case 'checkbox': ?>
      <?php break;
} ?>
<?php if($element->getScript()): ?>

<script type="text/javascript">
    <?php echo $element->getScript() ?>
</script>

<?php endif; ?>

1 Answer 1

2

Step 1: Add this code in your Block/Adminhtml/Devices/grid.php

static public function getOptionArray4()
{
              $data_array=array(); 
$data_array[0]='Tablet';
$data_array[1]='Smartphone';
     return($data_array);
}
static public function getValueArray4()
{
              $data_array=array();
foreach(Allin_Devices_Block_Adminhtml_Devices_Grid::getOptionArray4() as $k=>$v){
          $data_array[]=array('value'=>$k,'label'=>$v); 
}
          return($data_array);

}

Step 2: Add this code in your Block/Adminhtml/Devices/Edit/Tab/form.phtml

$fieldset->addField('mobile_tablet', 'select', array(
'name'  => 'mobile_tablet',
'label' => Mage::helper('devices')->__('Select Device Type'),
'values'   => Allin_Devices_Block_Adminhtml_Devices_Grid::getValueArray4()
));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.