multicheckboxes zend形式多人

hai*_*der 1 forms checkbox zend-framework

我想用多个复选框填充表单,并将多个复选框组合在一起,所以如果我选中了一个多重复选框,我将全部查看它们.正常填充不起作用.它只是给我一个复选框.这是我的代码.

public function addEditAction() {


    $id = (int) $this->_request->getParam('id');

    $request = $this->getRequest();

    $form = new Admin_Form_Tab();

    $db = Zend_Db_Table::getDefaultAdapter();

    if ($this->getRequest()->isPost()) {
        if ($form->isValid($request->getPost())) {
            if (isset($id) && $id != "") {
                $gettag = $form->getValue('tag_id');
                $gettags = count($gettag);
                try {
                    //shift the orders to
                    $select = $db->select()->from(array('t' => 'tab'), array('t.id',
                                't.title',
                                't.tab_position',
                                't.order',
                                't.is_active',
                                't.is_deleted'))->where('id = ?', $id);
                    $currentTab = $db->fetchRow($select);
                    $var3 = array('tab.order' => new Zend_Db_Expr('tab.order - 1'));
                    $var4 = array('tab.order >= ' . $currentTab['order'], 'is_active=1', 'is_deleted=0', 'tab_position=1');
                    $db->update('tab', $var3, $var4);
                    $var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
                    $var2 = array('tab.order >= ' . $form->getValue('order'), 'is_active=1', 'is_deleted=0', 'tab_position=1');
                    $db->update('tab', $var, $var2);
                    $db->delete('tab_tag', array('tab_id = ?' => $id));
                    foreach ($gettag as $value) {

                        $db->insert('tab_tag',
                                array(
                                    'tag_id' => $value,
                                    'tab_id' => $id
                        ));
                    }
                    $db->update('tab', array(
                        'title' => $form->getValue('title'),
                        'body' => $form->getValue('body'),
                        'is_active' => $form->getValue('is_active'),
                        'banner_link' => $form->getValue('banner_link'),
                        'tab_path' => $form->getValue('tab_path'),
                        'link_open' => $form->getValue('link_open'),
                        'tab_position' => $form->getValue('tab_position'),
                        'tab_parent' => $form->getValue('tab_parent')
                            ),
                            array('id =?' => $id));
                    $this->flash('Tab Updated', 'admin/tab');
                } catch (Exception $e) {

                    $this->flash($e->getMessage(), 'admin/tab');
                }
            } else {
                try {
                    $formValues = $form->getValues();
                    $formValues['created_by'] = 1;
                    $formValues['created_date'] = date('Y/m/d H:i:s');
                    $formValues['is_deleted'] = 0;

                    $var = array('tab.order' => new Zend_Db_Expr('tab.order + 1'));
                    $var2 = array('tab.order >= ' . $form->getValue('order'), 'is_active=1', 'is_deleted=0', 'tab_position=1');
                    $db->update('tab', $var, $var2);

                    foreach ($gettag as $value) {

                        $db->insert('tab_tag',
                                array(
                                    'tag_id' => $value,
                                    'tab_id' => $id
                        ));
                    }
                    $db->insert('tab', array(
                        'title' => $form->getValue('title'),
                        'body' => $form->getValue('body'),
                        'is_active' => $form->getValue('is_active'),
                        'banner_link' => $form->getValue('banner_link'),
                        'tab_path' => $form->getValue('tab_path'),
                        'link_open' => $form->getValue('link_open'),
                        'tab_position' => $form->getValue('tab_position'),
                        'tab_parent' => $form->getValue('tab_parent')
                    ));




                    $this->flash('Tab inserted', 'admin/tab');
                } catch (Exception $e) {
                    $this->flash($e->getMessage(), 'admin/tab');
                }
            }
        }
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */


    if (isset($id) && $id != "") {
        $values = $db->fetchRow($db->select()
                ->from(array('t'=>'tab'))
                ->joinLeft(array('tt'=>'tab_tag'), 'tt.tab_id = t.id'));
        $form->populate($values);
    }

    $this->view->form = $form;
}
Run Code Online (Sandbox Code Playgroud)

isc*_*odv 5

要填充multiheckbox,您必须为数组提供必须检查的复选框的键:

$values = array(
    'my_mylticheckbox' => array(1,3,5)
);
$form->populate($values);
Run Code Online (Sandbox Code Playgroud)

或者如果您只想选中一个复选框:

$values = array('my_multicheckbox' => 3);
$form->populate($values);
Run Code Online (Sandbox Code Playgroud)

因此,只需确保将数组作为multiheckbox的值传递.