Advertisement
01Kuzma

Zend_Form

Apr 3rd, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.68 KB | None | 0 0
  1. <?php
  2. class Forms_LpaManageEmailForm extends Zend_Form
  3. {
  4.     protected $_actionUrl;    
  5.     protected $_entry_id;
  6.     protected $_flag;
  7.  
  8.  
  9.     public function __construct($actionUrl, $options=null, $entry_id, $flag)
  10.     {
  11.         $this->addPrefixPath('ZFBlog_Form_Decorator', 'ZFBlog/Form/Decorator/', 'decorator');
  12.        
  13.         parent::__construct($options);
  14.         $this->setActionUrl($actionUrl);
  15.         $this->setEntryId($entry_id);
  16.         $this->setFlag($flag);
  17.         $this->init();     
  18.     }    
  19.    
  20.     public function setActionUrl($actionUrl) {
  21.        
  22.         $this->_actionUrl = $actionUrl;
  23.         return $this;
  24.     }    
  25.    
  26.     public function setEntryId($entry_id){        
  27.         $this->_entry_id = $entry_id;      
  28.         return $this;
  29.     }  
  30.    
  31.     public function getEntryId(){
  32.         return $this->_entry_id['entry_id'];
  33.     }
  34.    
  35.     public function setFlag($flag) {
  36.         $this->_flag = $flag;
  37.     }
  38.    
  39.     public function getFlag() {
  40.         return $this->_flag;
  41.     }    
  42.    
  43.    
  44.     public function init()
  45.     {      
  46.          
  47.         $this->setAction($this->_actionUrl)
  48.              ->setMethod('post')
  49.              ->setAttribs(array('id' => 'descriptionform', 'onSubmit' => 'multipleSelectOnSubmit()'));        
  50.        
  51.         $this->clearDecorators();
  52.        
  53.  
  54.     ...    
  55.        
  56.         $this->addElement('hidden', 'id', array(            
  57.             'validators' => array(
  58.                 'Digits'
  59.             ),
  60.             'required' => true,
  61.             'value' => $this->_entry_id['entry_id'],
  62.         ));
  63.  
  64.         ...
  65.  
  66.         $this->addElement($submit);
  67.        
  68.  
  69.        ...      
  70.     }
  71.    
  72.    
  73.     private function _addMultiOptionsForMultiSelect()
  74.     {
  75.             ...
  76.     }
  77.    
  78.     public function render(Zend_View_Interface $view = null)
  79.     {
  80.         $this->_addMultiOptionsForMultiSelect();
  81.    
  82.         return parent::render($view);
  83.     }
  84.    
  85.     public function isValid($data)
  86.     {
  87.         $this->_addMultiOptionsForMultiSelect();
  88.    
  89.         return parent::isValid($data);
  90.     }
  91.    
  92. }
  93.  
  94. <?php
  95. class Default_Form_CartReport extends Forms_LpaManageEmailForm
  96. {
  97.     protected $_orderId;    
  98.  
  99.     public function __construct($actionUrl, $options=null, $entry_id, $flag=null, $orderId)
  100.     {                      
  101.         $this->setOrderId($orderId);
  102.         parent::__construct($actionUrl, $options=null, $entry_id, $flag);
  103.     }
  104.    
  105.     public function setOrderId($orderId){
  106.    
  107.         $this->_orderId = $orderId;
  108.         return $this;
  109.     }
  110.  
  111.     public function setValue($value)
  112.     {
  113.         $strippedValue = stripslashes($value);
  114.         return parent::setValue($strippedValue);
  115.     }
  116.    
  117.     public function init(){          
  118.         parent::init();
  119.         $this->id->setValue('100'); // experimental method. doesn't work... debugger shows
  120.          //["_value":protected] => string(3) "100" ,  but in HTML output it's empty
  121.        
  122.        /* $this->addElement('hidden', 'id', array(
  123.                 'validators' => array(
  124.                         'Digits'
  125.                 ),
  126.                 'required' => true,
  127.                 'value' => '100',
  128.         ));*/ creating the element with the same name doesn't make any sense
  129.          
  130.        Zend_Debug::dump($this->getElements());
  131.                
  132.    }
  133.    
  134.    private function _addMultiOptionsForMultiSelect()
  135.    {
  136.        ...                     
  137.                        
  138.    }
  139.    
  140.    public function render(Zend_View_Interface $view = null)
  141.    {
  142.         $this->_addMultiOptionsForMultiSelect();
  143.    
  144.         return Zend_Form::render($view);
  145.    }
  146.    
  147.    public function isValid($data)
  148.    {
  149.         $this->_addMultiOptionsForMultiSelect();
  150.    
  151.         return Zend_Form::isValid($data);
  152.    }  
  153.          
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement