Skip to main content

Zend Form with Decorator Class

you have to make some changes in this code according to you need but it wil help you alot....

1: View:

<?php echo $this->food; ?>

<?php echo $this->cab; ?>


2:Controller:



 public function indexAction(){   


  $ReimbursermentFood=new Form_Webchutney( array('selectForm' => '__FOOD_REIMBURSEMENT'));
  $ReimbursermentCab=new Form_Webchutney( array('selectForm' => '__CAB_REIMBURSEMENT'));
$Employeearray=array();  
 


  $Employeearray['AccountManager']='Account Manager';

  $Employeearray['aktel']='aktel';
  $Employeearray['saurabh.patel']='saurabh patel';

  $ReimbursermentFood->setAction('/user/reimbursement/food');
  $ReimbursermentFood->setAttrib("id","foodForm");

  $AccountManager = $ReimbursermentFood->getElement('AccountManager');

  $AccountManager->setLabel('')
                ->addMultiOptions($Employeearray); 
   #$AccountManager->setValue("Aditya Kumar");
   $AccountManager->setAttrib('readonly', 'readonly');
  $this->view->Food=$ReimbursermentFood;


  $ReimbursermentCab->setAction('/user/reimbursement/cab');    
  $ReimbursermentCab->setAttrib("id","cabForm");

  $AccountManager = $ReimbursermentCab->getElement('AccountManager');
  #$AccountManager->setValue("Aditya Kumar");
   $AccountManager->setLabel('')
                ->addMultiOptions($Employeearray); 
   $AccountManager->setAttrib('readonly', 'readonly');
  #$ReimbursermentCab->removeElement("Amount");    
$this->view->Cab=$ReimbursermentCab;


 
}





3:Form:
_________________________________________

<?php

class Form_Aktel extends Zend_Form {
   

    /* @access Public
     * @var object
     */
   
    
     /* @access Public
     * @var object
     */
  

    public $REInput;
    public $REButton;

    
    protected $selectForm = '';

    public function setselectForm($param)  {
            $this->selectForm = $param;           
            
        } 

    
    private function decorator(){
 
                $this->REInput= New Form_Decorator_ReInput();
      $this->REButton= New Form_Decorator_ReButton(); 
      $this->RESETButton= New Form_Decorator_ResetButton();
      
 
  }


    
public function init() {
       
      $this->decorator(); 

 switch ($this->selectForm) 
            {  
            


          

            CASE '__FOOD_REIMBURSEMENT':

                $this->foodForm();
 
                break;    
 
CASE '__CAB_REIMBURSEMENT':

                $this->cabForm();
 
                break;     

}
 
    }
  
    private function foodForm()    {       
         
           
         
         $this->setMethod('post')  ;

        // date
$accountDate = $this->createElement('text', 'date');
$accountDate->setValue('Date');
$accountDate->setRequired(TRUE);
$accountDate->setAttrib('size', 30);
$accountDate->setDecorators(array($this->REInput)) ;
$accountDate->setAttrib('id','food_datepicker');
$accountDate->setAttrib('Class','date');


       // name
     $accountName = $this->createElement('text', 'Name');
$accountName->setValue('Name');
$accountName->setRequired(TRUE);
$accountName->setAttrib('size', 30);
        $accountName->setDecorators(array($this->REInput)) ;
        $accountName->setAttrib('id','food_Name');
$accountName->setAttrib('Class','txtfld');

// Project
     $accountProject = $this->createElement('text', 'Project');
$accountProject->setValue('Project');
$accountProject->setRequired(TRUE);
$accountProject->setAttrib('size', 30);
        $accountProject->setDecorators(array($this->REInput)) ;
        $accountProject->setAttrib('id','food_Project');
$accountProject->setAttrib('Class','txtfld');

// AccountManager
    /* 
     $accountAccountManager = $this->createElement('text', 'AccountManager');
$accountAccountManager->setValue('Account Manager');
$accountAccountManager->setRequired(TRUE);
$accountAccountManager->setAttrib('size', 30);
        $accountAccountManager->setDecorators(array($this->REInput)) ;
        $accountAccountManager->setAttrib('id','food_AccountManager');
$accountAccountManager->setAttrib('Class','txtfld');  
*/

        $accountAccountManager = new Zend_Form_Element_Select('AccountManager');
        


// Punch_time
     $accountPunch_time =$this->createElement('text', 'Punch_time');
$accountPunch_time->setValue('Punch Time');
$accountPunch_time->setRequired(TRUE);
$accountPunch_time->setAttrib('size', 30);
        $accountPunch_time->setDecorators(array($this->REInput)) ;
        $accountPunch_time->setAttrib('id','food_Punch_time');
$accountPunch_time->setAttrib('Class','time');

// Order_time
     $accountOrder_time =$this->createElement('text', 'Order_time');
$accountOrder_time->setValue('Order Time');
$accountOrder_time->setRequired(TRUE);
$accountOrder_time->setAttrib('size', 30);
        $accountOrder_time->setDecorators(array($this->REInput)) ;
        $accountOrder_time->setAttrib('id','food_Order_time');
$accountOrder_time->setAttrib('Class','time');


// Amount
     $accountAmount =$this->createElement('text', 'Amount');
$accountAmount->setValue('Billed Amount');
$accountAmount->setRequired(TRUE);
$accountAmount->setAttrib('size', 30);
        $accountAmount->setDecorators(array($this->REInput)) ;
        $accountAmount->setAttrib('id','food_Amount');
$accountAmount->setAttrib('Class','txtfld');
 
      

//submit
$accountSubmit =new Zend_Form_Element_Submit('Submit');
$accountSubmit->setDecorators(array($this->REButton)) ;

 

//submit
$accountButtom =new Zend_Form_Element_Button('Reset');
$accountButtom->setDecorators(array($this->RESETButton));  

 
     
     
   $accountFrom = $this->createElement('hidden', 'from')                 
            ->setValue(rand(1, 9999999999)); 
       
        // CSR
        $accountcsr = $this->createElement('hash', 'no_csr', array( 'salt' => 'unique'));
 
         
       $this->addElements(array($accountDate, $accountName ,$accountProject, $accountAccountManager,  $accountPunch_time, $accountOrder_time ,  $accountAmount  ,    $accountSubmit  , $accountButtom ,  $accountFrom,$accountcsr)); 
     
  $this->setDecorators(array( 'FormElements','Form'));

         
           
}
    


    private function cabForm()    {       
         
           
         
         $this->setMethod('post')  ;

        // date
$accountDate = $this->createElement('text', 'date');
$accountDate->setValue('Date');
$accountDate->setRequired(TRUE);
$accountDate->setAttrib('size', 30);
$accountDate->setDecorators(array($this->REInput)) ;
$accountDate->setAttrib('id','cab_datepicker');
$accountDate->setAttrib('Class','date');


       // name
     $accountName = $this->createElement('text', 'Name');
$accountName->setValue('Name');
$accountName->setRequired(TRUE);
$accountName->setAttrib('size', 30);
        $accountName->setDecorators(array($this->REInput)) ;
        $accountName->setAttrib('id','cab_Name');
$accountName->setAttrib('Class','txtfld');

// Project
     $accountProject = $this->createElement('text', 'Project');
$accountProject->setValue('Project');
$accountProject->setRequired(TRUE);
$accountProject->setAttrib('size', 30);
        $accountProject->setDecorators(array($this->REInput)) ;
        $accountProject->setAttrib('id','cab_Project');
$accountProject->setAttrib('Class','txtfld');

// AccountManager
    /* $accountAccountManager = $this->createElement('text', 'AccountManager');
$accountAccountManager->setValue('Account Manager');
$accountAccountManager->setRequired(TRUE);
$accountAccountManager->setAttrib('size', 30);
        $accountAccountManager->setDecorators(array($this->REInput)) ;
        $accountAccountManager->setAttrib('id','cab_AccountManager');
$accountAccountManager->setAttrib('Class','txtfld'); */

$accountAccountManager = new Zend_Form_Element_Select('AccountManager');
 //Pick_Up_Area for cab

$accountPick_Up_Area =$this->createElement('text', 'Pick_Up_Area');
$accountPick_Up_Area->setValue('Pickup Area');
$accountPick_Up_Area->setRequired(TRUE);
$accountPick_Up_Area->setAttrib('size', 30);
        $accountPick_Up_Area->setDecorators(array($this->REInput)) ;
        $accountPick_Up_Area->setAttrib('id','cab_Pick_Up_Area');
$accountPick_Up_Area->setAttrib('Class','picfrom');


        //Drop_Area for cab
$accountDrop_Area =$this->createElement('text', 'Drop_Area');
$accountDrop_Area->setValue('Drop Area');
$accountDrop_Area->setRequired(TRUE);
$accountDrop_Area->setAttrib('size', 30);
        $accountDrop_Area->setDecorators(array($this->REInput)) ;
        $accountDrop_Area->setAttrib('id','cab_Drop_Area');
$accountDrop_Area->setAttrib('Class','picto');
          
    }




         
           
}
      

     
          
     private function forgotPasswordForm() {

    $this->setMethod('post')
             ->setAttrib('id', 'forgotPassword')
             ->setAttrib('name', 'forgotPassword');
   
             
    $emailInput= $this->createElement('text', 'Email');
    $emailInput->setLabel('Enter your EmailID');
$emailInput->setRequired(TRUE);
$emailInput->setAttrib('size', 30);
$emailInput->setDecorators(array($this->Input)) ;
$emailInput->addValidator('NotEmpty', true, array('messages' => 'Error_Account_Missing_Email_Field' ));

//submit
$accountSubmit =new Zend_Form_Element_Submit('Submit');
$accountSubmit->setLabel('Submit');
$accountSubmit->setValue('Submit');  
    $accountSubmit->setDecorators(array($this->Button)) ;
$accountFrom = $this->createElement('hidden', 'from')                 
           ->setValue(rand(1, 9999999999));
     
       // CSR
   $accountcsr = $this->createElement('hash', 'no_csr', array( 'salt' => 'unique'));
$this->addElements(array($accountUsername,$accountPassword,$accountSubmit,$accountFrom,$accountcsr)); 
   $this->setDecorators(array( 'FormElements','Form'));
    
     
     }

}




4:Decorator:


_________________________________________________________________________________-

<?php
class Form_Decorator_ReSelect extends Zend_Form_Decorator_Abstract
{
protected $_format = '<div></div>';
   public function render($content)
{
$element = $this->getElement();
$name = htmlentities($element->getFullyQualifiedName());
$label = htmlentities($element->getLabel());
$id = htmlentities($element->getId());
$value = htmlentities($element->getValue());
$markup = sprintf($this->_format,$id, $name, $value);
return $markup;
}


}



__________________________________________________________________________________________


<?php
class Form_Decorator_ReInput extends Zend_Form_Decorator_Abstract
{


protected $_format ='<div class="frmbx">
                            <div class="txtbxlft"></div> 
    <div class="txtbxmid"><input type="text"  class="%s"  id="%s" name="%s"  value="%s" /><span>*</span></div> 
                            <div class="txtbxrht"></div> 
                        </div>';

   public function render($content)
{
$element = $this->getElement();

    
$Class=htmlentities($element->getAttrib("Class"));
$id = htmlentities($element->getAttrib("id"));
$name = htmlentities($element->getFullyQualifiedName());
$value = htmlentities($element->getValue());
$markup = sprintf($this->_format, $Class, $id, $name, $value);
return $markup;
}


}

____________________________________________________________________________________________


<?php
class Form_Decorator_ReButton extends Zend_Form_Decorator_Abstract
{
protected $_format ='<div class="frmbxsubmit">
                                              
                          <input id="%s" name="%s"  type="submit" value="" class="submitbtn">
                                                
                      </div>';

   public function render($content)
{
$element = $this->getElement();
$name = htmlentities($element->getFullyQualifiedName());
$label = htmlentities($element->getLabel());
$id = htmlentities($element->getId());
$value = htmlentities($element->getValue());
$markup = sprintf($this->_format,$id, $name);
return $markup;
}


}



Comments

Popular posts from this blog

Magento-Concept

1) Mcrypt : This is an interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes. Additionally, it supports RC6 and IDEA which are considered "non-free". CFB/OFB are 8bit by default. 2) Mhash : These functions are intended to work with » mhash. Mhash can be used to create checksums, message digests, message authentication codes, and more. This is an interface to the mhash library. Mhash supports a wide variety of hash algorithms such as MD5, SHA1, GOST, and many others. 3) Simplexml : The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators. 4) DOM : The DOM extension allows you to op  erate on XML documents through the DOM API with PHP 5. 5) InnoDB storage engine : InnoDB is ...

What are the advantages and disadvantages of using zsh instead of bash (or other shells)?

Everything y ou kno w from bash  still  applies, but zsh does a bunch of other useful things.  I  know that I use only a small subset of them, but t hese are especially useful for me: Extended globbing: For example,  *(.)  matches only regular files, not directories, whereas  a*z(/)  matches directories whose names start with  a  and end with  z . There are a bunch of other things, such as  **  as described by  Ole Tange . Inline glob expansion: For example, type  rm *.pdf  and then hit tab. The glob  *.pdf  will expand inline into the list of .pdf files, which means you can change the result of the expansion, perhaps by removing from the command the name of one particular file you don’t want to  rm . Interactive path expansion: Type  cd /u/l/b  and hit tab. If there is only one existing path each of whose components start...