0

http://magento.localhost.com/index.php/arithmetic/adminhtml_arithmetic/edit/id/5/key/c03c12d4c338a2e4cdbb93c3d9e511a93401d19b21a13ea77cffda20cac94577/

这就是我的链接的样子。我在编辑网格页面中通过 ID 获取所有值

有一个用于多个复选框的部分。如何根据结果数组选择所有复选框

$fieldset-> addField('st_user_interest', 'checkboxes', array(
        'label'     => Mage::helper('arithmetic')->__('Interest'),

        'required'  => true,
        'name'      => 'st_user_interest[]',
    'values'    => array(

        array(
            'label'     => Mage::helper('arithmetic')->__('Education'),
            'value'     => 'education',
        'class'     => 'required-one',

        ),
        array(
           'label'     => Mage::helper('arithmetic')->__('Business'),
            'value'     => 'business',
          'class'     => 'required-one',

        ),
        array(
            'label'     => Mage::helper('arithmetic')->__('Marketing'),
            'value'     => 'marketing',
         'class'     => 'required-one',

        ),

        array(
            'value'     => 'investment',
            'label'     => Mage::helper('arithmetic')->__('Investment'),
         'class'     => 'required-one',
        )
        ),      

    ));

谢谢

4

1 回答 1

0

嗨,在存储数组字段值时,我们在将数组转换为字符串后将其存储为字符串,

所以在 setValues() Magento 寻找与数组相同的输入字段值来检查复选框时

诀窍是将存储的字符串值转换为数组并分配给可以工作的列字段

Package_Arithmetic_Block_Adminhtml_Arithmetic_Edit_Tab_Form

protected function _prepareForm()
{

 $id = $this->htmlEscape(Mage::registry('arithmetic_data')->getIn_user_id());
$model = Mage::getModel("arithmeti/newuser")->load($id);

/* here is the stuff witch converting the stored string to array and set in                          st_user_interest */
$interest = $model->getSt_user_interest();
$model->setSt_user_interest(explode(',',$interest));


    $form = new Varien_Data_Form();
    $this->setForm($form);
    $fieldset = $form->addFieldset('arithmetic_form', array('legend'=>Mage::helper('arithmetic')->__('User information')));


  $fieldset-> addField('st_user_interest', 'checkboxes', array(
    'label'     => Mage::helper('arithmetic')->__('Interest'),

    'required'  => true,
    'name'      => 'st_user_interest[]',
'values'    => array(

    array(
        'label'     => Mage::helper('arithmetic')->__('Education'),
        'value'     => 'education',


    ),
    array(
       'label'     => Mage::helper('arithmetic')->__('Business'),
        'value'     => 'business',


    ),
    array(
        'label'     => Mage::helper('arithmetic')->__('Marketing'),
        'value'     => 'marketing',


    ),

    array(
        'value'     => 'investment',
        'label'     => Mage::helper('arithmetic')->__('Investment'),

    )
    ),      

));

if ( Mage::getSingleton('adminhtml/session')->getArithmeticData() )
    {

        $form->setValues(Mage::getSingleton('adminhtml/session')->getArithmeticData());
        Mage::getSingleton('adminhtml/session')->setArithmeticData(null);
    } elseif ( $model->getData() ) {


    //Mage::registry('arithmetic_data')->getData(); /* removing this line and adding $model->getData() inslde the $form->setValues() */
        $form->setValues($model->getData());

    } 


    return parent::_prepareForm();

}
于 2013-06-14T08:11:50.003 回答