2015-01-12 42 views
0

我有一個magento管理面板中的表單。在表格中,我有複選框,我可以選擇多個選項或一個。問題是我無法對此進行驗證。因爲沒有選擇任何選項,我可以保存記錄。我的代碼如下:Magento問題與添加驗證到多選複選框

$fieldset-> addField('time_ranges', 'checkboxes', array(
      'label'  => Mage::helper('CheckoutTime')->__('Time Ranges'), 

      'required' => true, 
      'class'  => 'required-entry', 
      'name'  => 'time_ranges[]', 
      'values' => array(
       array(
        'label'  => Mage::helper('CheckoutTime')->__('Education'), 
        'value'  => 'education', 

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

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

       ), 

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

     )); 

任何人都可以請告訴我如何添加驗證到這種形式。

謝謝

+0

這種方式是正確的。我的編碼在其他地方出現了一些問題。這就是爲什麼它沒有提前工作。否則,這是正確的做法。 – KNKM

回答

0

嘗試通過改變

'name'  => 'time_ranges[]' 

'name'  => 'time_ranges' 
+0

這種方式只能用於選擇一個值。要選擇多個值,您需要使用'time_ranges []' – KNKM

0

這種方式是正確的。我的編碼在其他地方出現了一些問題。這就是爲什麼它沒有提前工作。否則,這是做到這一點的正確方法。