You need to set the field for multi-select as
$fieldset->addField("visible_in", "multiselect", array(
"label" => Mage::helper("slider")->__("Visible In"),
"name" => "visible-in",
'values' => $this->getOptionArray(),
'required' => true,
));
In this Most important value, here we are calling the function to select categories
'values' => $this->getOptionArray(),
In the same file write this code
const REPEATER = '_';
const PREFIX_END = '';
protected $_options = array();
public function getOptionArray($parentId = 1, $recursionLevel = 3)
{
$recursionLevel = (int)$recursionLevel;
$parentId = (int)$parentId;
$category = Mage::getModel('catalog/category');
/* @var $category Mage_Catalog_Model_Category */
$storeCategories = $category->getCategories($parentId, $recursionLevel, TRUE, FALSE, TRUE);
foreach ($storeCategories as $node) {
/* @var $node Varien_Data_Tree_Node */
$this->_options[] = array(
'label' => $node->getName(),
'value' => $node->getEntityId()
);
if ($node->hasChildren()) {
$this->_getChildOptions($node->getChildren());
}
}
return $this->_options;
}
/**
* @param Varien_Data_Tree_Node_Collection $nodeCollection
*/
protected function _getChildOptions(Varien_Data_Tree_Node_Collection $nodeCollection)
{
foreach ($nodeCollection as $node) {
/* @var $node Varien_Data_Tree_Node */
$prefix = str_repeat(self::REPEATER, $node->getLevel() * 1) . self::PREFIX_END;
$this->_options[] = array(
'label' => $prefix . $node->getName(),
'value' => $node->getEntityId()
);
if ($node->hasChildren()) {
$this->_getChildOptions($node->getChildren());
}
}
}
The output for this is as
This worked for me.
Thanks.