예제 #1
0
 public function init()
 {
     // Set the method for the display form to POST
     $this->setMethod('post');
     $this->setAttribs(array('class' => 'form-horizontal'));
     $decoratorField = new My_Decorator_FieldLogin();
     $elements = array();
     // Add email field
     $input = new Zend_Form_Element_Text('email', array('required' => true, 'label' => 'Email Address:', 'id' => 'email', 'placeholder' => 'Your email..', 'class' => 'form-control', 'type' => 'email'));
     $validator = new Zend_Validate_EmailAddress();
     $validator->setOptions(array('domain' => false));
     $input->addValidators(array($validator, new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add password field
     $input = new Zend_Form_Element_Password('password', array('required' => true, 'label' => 'Password:'******'id' => 'password', 'class' => 'form-control', 'placeholder' => 'Your password..'));
     $input->addValidators(array(new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add checkbox field
     $input = new Zend_Form_Element_Checkbox('rememberMe', array('label' => 'Remember me', 'id' => 'rememberMe', 'class' => 'checkbox', 'type' => 'checkbox'));
     $decoratorCheckBox = new My_Decorator_CheckBox();
     $input->addDecorator($decoratorCheckBox);
     $elements[] = $input;
     $input = new Zend_Form_Element('resetpass', array('label' => 'Reset your password', 'id' => 'resetpass', 'class' => 'form-control', 'value' => 'resetpass'));
     $input->addDecorator(new My_Decorator_AnchoraForm());
     $elements[] = $input;
     //Add Submit button
     $input = new Zend_Form_Element_Submit('submit', array('Label' => '', 'class' => 'btn btn-default', 'value' => 'Login'));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     $this->addElements($elements);
     $this->addDisplayGroup(array('email', 'password', 'resetpass', 'rememberMe', 'submit'), 'displgrp', array('decorators' => array('FormElements', 'Fieldset')));
 }
예제 #2
0
파일: Form.php 프로젝트: nhochong/qlkh-sgu
 /**
  * Adds default decorators to an existing element
  * 
  * @param Zend_Form_Element $element
  */
 public static function addDefaultDecorators(Zend_Form_Element $element)
 {
     $fqName = $element->getName();
     if (null !== ($belongsTo = $element->getBelongsTo())) {
         $fqName = $belongsTo . '-' . $fqName;
     }
     $element->addDecorator('Description', array('tag' => 'p', 'class' => 'description', 'placement' => 'PREPEND'))->addDecorator('HtmlTag', array('tag' => 'div', 'id' => $fqName . '-element', 'class' => 'form-element'))->addDecorator('Label', array('tag' => 'div', 'tagOptions' => array('id' => $fqName . '-label', 'class' => 'form-label')))->addDecorator('HtmlTag2', array('tag' => 'div', 'id' => $fqName . '-wrapper', 'class' => 'form-wrapper'));
 }
 /**
  * Will set up a task-element and decorators
  * @param string $id
  * @param array $values
  * @param array $attribs
  * @return Zend_Form_Element
  */
 protected function createTaskElement($id, $values, $isNew = false)
 {
     $elm = new Zend_Form_Element((string) $id);
     $elm->clearDecorators();
     $elm->addDecorator(new My_Decorator_TaskElement());
     $elm->addDecorator('Errors', array('placement' => 'prepend'));
     // add configured validator
     $validator = new My_Validator_TaskElement();
     $validator->setIsNew($isNew);
     $elm->addValidator($validator);
     return $elm;
 }
 public function getSaveProductForm($id)
 {
     $form = new Zend_Form();
     //get product whitch want update
     $productMapper = new Application_Model_ProductMapper();
     $product = new Application_Model_Product();
     if ($id) {
         $product = $productMapper->getProductById($id);
     }
     // Set the method for the display form to POST
     $form->setMethod('post');
     $form->setAttribs(array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data'));
     $decoratorField = new My_Decorator_Field();
     $elements = array();
     //Add id hidden field
     $input = new Zend_Form_Element_Hidden('id', array('value' => $id));
     $elements[] = $input;
     // Add name field
     $input = new Zend_Form_Element_Text('name', array('required' => true, 'label' => 'Name:', 'id' => 'name', 'placeholder' => 'Type something..', 'value' => $product->getName(), 'class' => 'form-control'));
     $input->addValidators(array(new Zend_Validate_Alnum(), new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     // Add category field
     $select = new Zend_Form_Element_Select('category_id', array('required' => true, 'label' => 'Category:', 'id' => 'category', 'class' => 'form-control'));
     $categoryMapper = new Application_Model_CategoryMapper();
     $categories = $categoryMapper->fetchAll();
     foreach ($categories as $category) {
         $select->addMultiOption($category->getId(), $category->getName());
     }
     // set selected option
     $select->setValue($product->getCategoryId());
     $select->addDecorator($decoratorField);
     $elements[] = $select;
     $currencyMapper = new Application_Model_CurrencyMapper();
     $currency = $currencyMapper->getDefaultCurrency();
     // Add Price field
     $input = new Zend_Form_Element_Text('price', array('required' => true, 'label' => 'Price in ' . $currency->getCode() . ':', 'id' => 'price', 'placeholder' => 'Type something..', 'value' => number_format((double) $product->price, 2), 'class' => 'form-control', 'min' => self::MIN, 'max' => self::MAX, 'step' => 'any', 'type' => 'number'));
     $min = new Zend_Validate_LessThan(self::MAX);
     $max = new Zend_Validate_GreaterThan(self::MIN);
     $input->addValidators(array(new Zend_Validate_Float(), $min, $max, new Zend_Validate_NotEmpty()));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     if ($id) {
         //Add File field
         if ($product->file) {
             $input = new Zend_Form_Element('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control', 'value' => $product->file));
             $input->addDecorator(new My_Decorator_AnchoraFileForm());
             $elements[] = $input;
         } else {
             $input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
             $input->addDecorator($decoratorField);
             $elements[] = $input;
         }
         //Add Image field
         if ($product->image) {
             $input = new Zend_Form_Element('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control', 'value' => $product->image));
             $input->addDecorator(new My_Decorator_ImageForm());
             $elements[] = $input;
         } else {
             $input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
             $input->addDecorator($decoratorField);
             $elements[] = $input;
         }
     } else {
         //Add File field
         $input = new Zend_Form_Element_File('file', array('label' => 'File:', 'id' => 'file', 'class' => 'form-control'));
         $input->addDecorator($decoratorField);
         $elements[] = $input;
         //Add Image field
         $input = new Zend_Form_Element_File('image', array('label' => 'Image:', 'id' => 'image', 'class' => 'form-control'));
         $input->addDecorator($decoratorField);
         $elements[] = $input;
     }
     //Add Description field
     $input = new Zend_Form_Element_Textarea('description', array('label' => 'Description:', 'id' => 'description', 'class' => 'form-control', 'value' => $product->description));
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     //Add Submit button
     if (!$id) {
         $input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-success', 'value' => 'Add New Product'));
     } else {
         $input = new Zend_Form_Element_Submit('submit', array('Label' => ' ', 'class' => 'btn btn-info', 'value' => 'Update Product'));
     }
     $input->addDecorator($decoratorField);
     $elements[] = $input;
     $form->addElements($elements);
     $form->addDisplayGroup(array('name', 'category_id', 'price', 'currency_id', 'file', 'image', 'description', 'submit'), 'displgrp', array('legend' => 'Add Products', 'decorators' => array('FormElements', 'Fieldset')));
     return $form;
 }
 /**
  * Setup per-element properties like labels, and classes
  */
 protected function setupSingleElement(Zend_Form_Element $elm)
 {
     // determine if this element has an error. (Will be used below)
     $elmHasError = count($elm->getMessages()) > 0;
     // set element values from the language pack
     $elm->setLabel($this->lang->get('form.label.' . $elm->getName()));
     // display info about required length if validator exists
     if ($elm->getValidator('StringLength')) {
         $elm->setDescription(sprintf($this->lang->get('form.description.' . $elm->getName()), $elm->getValidator('StringLength')->getMin(), $elm->getValidator('StringLength')->getMax()));
     } else {
         $elm->setDescription($this->lang->get('form.description.' . $elm->getName()));
     }
     // Duplicating type attr to classname in case we need to support IE6
     // and want to be able to directly target the element without using
     // input[type=text]
     $zendType = $elm->getType();
     $className = strtolower(substr($zendType, strrpos($zendType, '_') + 1));
     $elm->setAttrib('class', $className);
     // wrap this stuff up in a html div with class 'element'
     $elm->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'element'));
     // determine if element has error and use that to determine prefix char.
     // 1. There seems to be no way to add html to the reqPrefix
     // 2. There seems to be no way to add a custom classname to the div tag
     if ($elm->getName() != 'submit') {
         $reqChar = $elmHasError ? '! ' : '* ';
         $elm->addDecorator('Label', array('placement' => 'prepend', 'tag' => 'div', 'requiredPrefix' => $reqChar));
     }
     // use custom error decorator that attempts to replace default error
     // messages by the ones supplied by My_LanguagaPack
     $errorDecorator = new My_Decorator_Errors();
     $errorDecorator->setLanguagePack($this->lang);
     $elm->addDecorator($errorDecorator);
     // wrap everything so far in a li tag, give it class error if elm has error
     // ATT: using array to create alias for allready used HtmlTag decorator
     $liClass = $elmHasError ? 'error' : '';
     $elm->addDecorator(array('outerLi' => 'HtmlTag'), array('tag' => 'li', 'class' => $liClass));
 }
예제 #6
0
파일: Form.php 프로젝트: abdala/la
 public function decorateElement(Zend_Form_Element $element)
 {
     if (!$element instanceof Zend_Form_Element_File) {
         $element->addDecorator('ViewHelper');
     }
     $element->addDecorator('HtmlTag', array('tag' => 'div'));
     $element->addDecorator('Label', array('tag' => null));
     $element->addDecorator(array('wrapper' => 'HtmlTag'), array('tag' => 'div', 'class' => 'form-group col-sm-3'));
     return $element;
 }