2

I have a three table in my database, article category and art_cat

article has the id,name,status of the article

category has id,name,status of the category

art_cat has id,art_id and cat_id in the tables.

I have the values inserted respectively, but in my "article form" my category values are not coming selected. I have a multi select dropdown for the category. I have a distinct form for "category". that means my "article form" data goes in article table and "category form" data goes in art_cat table.

$fieldset->addField('category_id', 'multiselect', array(
 'label' => 'Category',
 'name' => 'category_id[]',
 'values' => Mage::helper('blog')->getCategoryOptionValues(true),
 'disabled' => false,
 'index' => 'category_id',
 ));

and here is my helper file Data.php

static function getCategoryOptionValues($inlcudeNone = false) {
 $collection = Mage::getModel('blog/blog')->getCollection();
 $values = array();
 if ($inlcudeNone){
 $values[] = array('label' => "--None--", 'value' => 0);
 }
 foreach ($collection as $category) {
 $values[] = array('label' => $category->getName(), 'value' => $category->getId());
 }
 return $values;
 }

How can I get the selected value for the category multi select dropdown. Please somebody help me with this.

asked Feb 12, 2014 at 13:54

1 Answer 1

0

During the addField call you can specify the option value. For normal field types this takes a string and will set this as the field value, but for multiple select fields you can specify a comma separated string containing each selected value.

answered Feb 17, 2014 at 21:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.