2014-09-02 49 views
0

我在我的zend窗體中有一個公共函數,稱爲select,其中它的consisit和element選擇添加addmultioptions,每個addmultioption都有一個特定的窗體,它在選擇後出現,有些窗體雖然由datepickers組成,但我有一個問題選擇與datepickers這些選擇字段。我記住我正在使用Jquery,並且在我的application.ini文件中包含了Zendx長度,並試圖擴展ZendX_JQuery_Form類。Zend Form DatePicker

我有一些與datepickers使用相同的方法爲每個表單,但不知道這是怎麼回事。下面是我的代碼。

繼承人我的代碼下面的例子。

<?php 

class Form_Excel extends ZendX_JQuery_Form //Tried Both methods normally use the one below 
class Form_Excel extends Zend_Form 
{ 
    public function init() 
    { 
} 


    public function excel() 
    { 
     $type = new Zend_Form_Element_Select('type'); 
     $type->setLabel('Select a Type:') 
      ->addMultiOption('1', ' Report1') 
      ->addMultiOption('2', ' Report2') 
      ->addMultiOption('3', ' Report3') 
      ->addMultiOption('4', ' Report4') 
      ->addMultiOption('5', ' Export5') 
      ->addMultiOption('6', ' Report6') 
      ->addMultiOption('7', ' Report7') 
      ->addmultiOption('8', ' Report8'); 

     $type->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box','style' => 'padding-left:0;padding-top:10px;margin-bottom: -35px;clear: both;')) 
      ->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-custom search-width span5')))); 

     $this->addElement($type); 
    } 

    public function 1() 
    { 
     $hidden = new Zend_Form_Element_Hidden('hidden'); 
     $hidden->setValue('status'); 
     $this->addElement($hidden); 

     $status = new Zend_Form_Element_Select('status'); 
     $status->setLabel('Current Status: ') 
        ->addMultiOption('', '--Select One--') 
        ->addMultiOption(1, 'First') 
        ->addMultiOption(2, 'Second') 
        ->addMultiOption(3, 'Contacted') 

       ->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box','style' => 'padding-left:0;padding-top:10px;clear: both;')); 

     $status->setAttribs(array('class' => 'col-md-12 form-control')); 

     $this->addElement($status); 

     //Assessed Before/After 
     $before = new ZendX_JQuery_Form_Element_DatePicker('before'); 
     $before  ->setLabel('Date Before: ') 
        ->addFilter('StripTags'); 
     $before  ->setJQueryParams(array(
        'dateFormat'=>'yy-mm-dd', 
        'changeMonth'=> true, 
        'changeYear'=> true 
        )) 
        ->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-4 field-box the-font print-container','style' => 'padding-left:0;padding-top:10px;')); 


     $before->setAttribs(array('class' => 'col-md-4 form-control the-font text-field')); 

     $this->addElement($before);   

     $after = new ZendX_JQuery_Form_Element_DatePicker('after'); 
     $after ->setLabel('Date After: ') 
        ->addFilter('StripTags'); 
     $after ->setJQueryParams(array(
        'defaultDate' => date('d-m-y'), 
        'changeMonth'=> true, 
        'changeYear'=> true 
        )) 
        ->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-4 field-box the-font print-container','style' => 'padding-left:0;padding-top:10px;')); 


     $after->setAttribs(array('class' => 'col-md-4 form-control the-font text-field')); 

     $this->addElement($after); 


     $submit = new Zend_Form_Element_Submit('submit'); 
     $submit ->setLabel('Submit') 
       ->setAttrib('class', 'btn-flat primary') 
       ->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','style' => 'width: 88%; padding-left:0;clear: both;')); 
     $this->addElement($submit); 
    } 
} 

回答

0

當使用:

$this->view->form = new Form_Excel(); 

即通常僅執行窗體的init()方法。

要執行另一個方法,我們仍然會實例化這個類,然後調用一個方法。

例如。

$this->view->form->excel(); 

然後在視圖:

<?= $this->form ?> 

將返回select元件。

+0

你說的是這個$ form = new Form_Excel(); $ form-> excel();其中我已經在控制器和<?phpecho $ this-> form;?>中,在我的視圖窗體中,但是我不能在datepicker字段上選擇,我不能選擇該字段並選擇一個日期 – 2014-09-02 12:15:32

+1

是的,因爲您沒有爲日期選擇器擴展'ZendX_Jquery_Form',這是必需的,而且如果它由'ajax'裝載,它仍然無法工作,您將需要使用'。 datepicker()'jquery方法:http://jqueryui.com/datepicker/ – surfer190 2014-09-02 12:17:35

+0

如何來一些我沒有實現ZendX_Jquery_Form的形式,但他們仍然工作?我試過,但即時通訊嘗試再次只是爲了檢查我是否沒有遺漏任何東西 – 2014-09-02 12:23:54