2009-08-12 68 views
3
<?php 
class Form_Audience extends Zend_Form_SubForm 
{ 
    public function init() 
    { 
     $this->setMethod('post'); 
     $this->setLegend('Audience Details'); 

     $this->addElement('text', 'audience_total', array(
      'label'  => 'Audience Total :', 
      'required' => true, 
      'filters' => array('Digits'), 
      'size'  => 15, 
      'validators' => array(
        'Digits', 
       ) 
      )); 


.... remaining code ..... 

請幫助修改上述代碼以應用GreaterThan驗證。若要添加驗證GreaterThan - Zend表格

感謝

回答

4

以下是我會做:

$eElement=new Zend_Form_Element_Text('audience_total'); 
$eElement->setLabel('Audience Total'); 
$eElement->setRequired(true); 
$eElement->setFilters(Array('Digits')); 
$eElement->size(15); 
$validator=new Zend_Validate_Digits(); 
$eElement->addValidator($validator,true); 
$validator=new Zend_Validate_GreaterThan(1); 
$eElement->addValidator($validator,true); 
$this->addElement(true); 
+0

感謝回覆,可以請你告訴我,你將如何修改上面的代碼做同樣的事情。 – Ish 2009-08-12 12:41:15

+0

基本上用我的塊代替$ this-> addElement ...行。 – 2009-08-12 14:56:23