Ejemplo n.º 1
0
 /**
  * Render element
  *
  * @param Zend_Form_Element $element
  * @return string
  */
 public function aElement(Zend_Form_Element $element)
 {
     $viewClasses = array($element->getAttrib('class'));
     if ($element->isRequired()) {
         if (!$element->getAttrib('title')) {
             $element->setAttrib('title', 'Field is required');
         }
         $viewClasses[] = 'aForm-field-required';
     }
     if ($element->getValidators()) {
         $viewClasses[] = 'aForm-field-validate';
     }
     if ($element->hasErrors()) {
         $viewClasses[] = 'aForm-field-invalid';
     } elseif ($element->getValue() || !$element->isRequired()) {
         $viewClasses[] = 'aForm-field-valid';
     }
     if ($element->getValidators()) {
         $viewClasses[] = 'aForm-field-validate';
     }
     $element->setAttrib('class', implode(' ', $viewClasses));
     $options = null;
     $separator = null;
     if ($element instanceof Zend_Form_Element_Multi) {
         $options = $element->getMultiOptions();
         $separator = $element->getSeparator();
     }
     return $this->view->{$element->helper}($element->getName(), $element->getValue(), $element->getAttribs(), $options, $separator);
 }
 /**
  * Enter description here ...
  * @param Zend_Form_Element $element
  * @author Tung Ly
  */
 public function renderFormElement($element, $vertical = 0)
 {
     if ($element->getType() != "Zend_Form_Element_Checkbox") {
         $element->setAttrib('class', $element->getAttrib('class') . ' form-control');
     }
     if ($element->isRequired()) {
         $element->setLabel($element->getLabel() . ' *');
         $element->setAttrib('class', $element->getAttrib('class') . ' required');
     }
     switch ($element->getType()) {
         case 'Zend_Form_Element_Textarea':
             $element->setAttrib('rows', 5);
             $element->setAttrib('cols', 80);
             break;
         case 'Zend_Form_Element_Hidden':
             return $element;
         default:
             break;
     }
     $error = '';
     if ($element->hasErrors()) {
         $error = 'has-error';
     }
     if ($element->getType() == 'Zend_Form_Element_Textarea') {
     }
     $btn = array('Zend_Form_Element_Submit', 'Zend_Form_Element_Reset');
     if (in_array($element->getType(), $btn)) {
         //$t ='<button type="reset" class="btn"><i class="icon-refresh"></i> '.$element->getLabel().'</button>';
         $t = '<div class="span2">' . $element . '</div>';
     } else {
         $label = trim(preg_replace("/([A-Z])/", " \$1", "{$element->getLabel()}"), ' ');
         $variables = array('%%ERROR_CLASS%%' => $error, '%%ELEMENT_NAME%%' => $element->getName(), '%%ELEMENT_LABEL%%' => $label, '%%ELEMENT%%' => $element, '%%HELP_MESSAGE%%' => current($element->getMessages()));
         $t = str_replace(array_keys($variables), $variables, $this->_getTemplate($vertical));
     }
     return $t;
 }
Ejemplo n.º 3
0
 public function testPassingConfigObjectToConstructorSetsObjectState()
 {
     $config = new Zend_Config($this->getOptions());
     $element = new Zend_Form_Element($config);
     $this->assertEquals('changed', $element->getName());
     $this->assertEquals('foo', $element->getValue());
     $this->assertEquals('bar', $element->getLabel());
     $this->assertEquals(50, $element->getOrder());
     $this->assertFalse($element->isRequired());
     $this->assertEquals('bar', $element->foo);
     $this->assertEquals('bat', $element->baz);
 }
Ejemplo n.º 4
0
 /**
  * Fügt angepasste Nachrichten für Validierungen hinzu.
  * @param Zend_Form_Element $element
  */
 protected function applyCustomMessages($element)
 {
     if ($element->isRequired()) {
         // wenn Validator 'notEmpty' bereits gesetzt ist; nicht modifizieren
         if (!$element->getValidator('notEmpty') && $element->autoInsertNotEmptyValidator()) {
             $notEmptyValidator = new Zend_Validate_NotEmpty();
             $notEmptyValidator->setMessage('admin_validate_error_notempty');
             $element->addValidator($notEmptyValidator);
         }
     }
 }
 /**
  * Gets html content fot label
  *
  * @param Zend_Form_Element $element
  * @return string 
  */
 protected function getLabelHTML($element)
 {
     $label = $element->getLabel();
     if ($translator = $element->getTranslator()) {
         $label = $translator->translate($label);
     }
     $label = $element->getView()->formLabel($element->getName(), $label);
     if ($element->isRequired()) {
         $label .= '<span class="asterisk">*</span>';
     }
     return $label;
 }