public function init() { $this->setMethod('post'); $cat = new Zend_Form_Element_Select('G_P_CAT'); $cat->setLabel('Kategorie: ')->addValidator('alnum')->setRequired(true)->addMultiOptions(array('Adresse' => 'Adresse', 'Falle' => 'Falle', 'Brutstätte' => 'Brutstätte')); $name = new Zend_Form_Element_Text('G_P_NAME'); $name->setLabel('Name: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true))->setRequired(true); $lat = new Zend_Form_Element('G_P_LAT'); $lat->setLabel('Lat: ')->setRequired(true)->addValidator('Between', true, array(0, 180)); $lng = new Zend_Form_Element('G_P_LNG'); $lng->setLabel('Lon: ')->setRequired(true)->addValidator('Between', true, array(0, 180)); $submit = new Zend_Form_Element_Submit('senden'); $this->addElements(array($name, $cat, $lat, $lng, $submit)); }
public function init() { $this->setMethod('post'); $typ = new Zend_Form_Element_Select('G_TYP'); $typ->setLabel('Typ: ')->addValidator('alnum')->setRequired(true)->addMultiOptions(array(1 => 'Adresse', 2 => 'Falle', 3 => 'Brutstätte')); $name = new Zend_Form_Element_Text('G_NAME'); $name->setLabel('Name: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true))->setRequired(true); $lat = new Zend_Form_Element('G_LAT'); $lat->setLabel('Lat: ')->setRequired(true)->addValidator('Between', true, array(0, 180)); $lon = new Zend_Form_Element('G_LON'); $lon->setLabel('Lon: ')->setRequired(true)->addValidator('Between', true, array(0, 180)); $submit = new Zend_Form_Element_Submit('senden'); $this->addElements(array($name, $typ, $lat, $lon, $submit)); }
/** * Creates the registration form and it's elements. * Also sets the validation techniques for the fields */ function __construct() { parent::__construct(); $this->setName('Registration'); $this->setMethod('POST'); $this->setAction('/user/register'); $username = new Zend_Form_Element('username'); $username->setLabel('Username'); $username->setRequired(true); $username->addValidator('NotEmpty', true); $username->addValidator(new Zend_Validate_StringLength(6, 10), true); $username->addValidator('Alnum', true); $username->addValidator(new User_Models_Forms_Validators_IsUnique('username')); $password = new Zend_Form_Element_Password('password'); $password->setLabel('Password'); $password->setRequired(true); $password->addValidator('NotEmpty', true); $password->addValidator(new Zend_Validate_StringLength(6, 10)); $gender = new Zend_Form_Element_Select('gender'); $gender->setLabel('Gender'); $gender->setMultiOptions(array('Male' => 'Male', 'Female' => 'Female')); $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email'); $email->setRequired(true); $email->addValidator('NotEmpty', true); $email->addValidator(new User_Models_Forms_Validators_EmailAddress(), true); $email->addValidator(new User_Models_Forms_Validators_IsUnique('email')); $paymentEmail = new Zend_Form_Element_Text('paymentEmail'); $paymentEmail->setLabel('Payment Email'); $paymentEmail->setRequired(true); $paymentEmail->addValidator('NotEmpty', true); $paymentEmail->addValidator(new User_Models_Forms_Validators_EmailAddress(), true); $paymentEmail->addValidator(new User_Models_Forms_Validators_IsUnique('paymentEmail')); $countries = new Zend_Form_Element_Select('country'); $countries->setMultiOptions(self::getCountries()); $countries->setLabel('Country'); $countries->addValidator('NotEmpty'); $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel('Register'); $this->addElements(array($username, $password, $gender, $email, $paymentEmail, $countries, $submit)); }
function __construct() { parent::__construct(); $this->setName('Registration'); $this->setMethod('POST'); $this->setAction('/user/login'); $username = new Zend_Form_Element('username'); $username->setLabel('Username'); $username->setRequired(true); $username->addValidator('NotEmpty', true); $username->addValidator(new Zend_Validate_StringLength(6, 10)); $username->addValidator('Alnum', true); $password = new Zend_Form_Element_Password('password'); $password->setLabel('Password'); $password->setRequired(true); $password->addValidator('NotEmpty', true); $password->addValidator(new Zend_Validate_StringLength(6, 10)); $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel('Register'); $this->addElements(array($username, $password, $submit)); }
/** * 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)); }
public function init() { $this->setMethod('post'); $g_name = new Zend_Form_Element_Text('G_NAME'); $g_name->setLabel('Name des Punktes: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true))->setRequired(true); $lat = new Zend_Form_Element('G_LAT'); $lat->setLabel('Lat: ')->setRequired(true)->addValidator('Between', true, array(0, 180)); //->setAttrib('disabled', 'true'); $lon = new Zend_Form_Element('G_LON'); $lon->setLabel('Lon: ')->setRequired(true)->addValidator('Between', true, array(0, 180)); //->setAttrib('disabled', 'true'); $b_name = new Zend_Form_Element_Text('B_NAME'); $b_name->setLabel('Name der Brutstaette: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true))->setRequired(true); $groesse = new Zend_Form_Element('B_GROESSE'); $groesse->setLabel('Größe: ')->setRequired(true)->addValidator('Int')->addValidator('Between', true, array(0, 100)); $gewaesser_art = new Zend_Form_Element_Text('B_GEWAESSER_ART'); $gewaesser_art->setLabel('Gewässer Art: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true)); $zugang = new Zend_Form_Element_Text('B_ZUGANG'); $zugang->setLabel('Zugang: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true)); $bek_art = new Zend_Form_Element_Text('B_BEK_ART'); $bek_art->setLabel('Bekämpfung Art: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true)); $text = new Zend_Form_Element_Textarea('B_TEXT'); $text->setLabel('Text: ')->addValidator('Alnum', true, array('allowWhiteSpace' => true))->setAttrib('rows', '5')->setAttrib('cols', '50'); $submit = new Zend_Form_Element_Submit('senden'); $this->addElements(array($g_name, $lat, $lon, $b_name, $groesse, $gewaesser_art, $zugang, $bek_art, $text, $submit)); //Layout $this->addDisplayGroup(array('G_NAME', 'G_LAT', 'G_LON'), 'geopoint', array('legend' => 'Koordinaten des Punktes')); $contact = $this->getDisplayGroup('geopoint'); $contact->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'openOnly' => true, 'style' => 'float:left;')))); $this->addDisplayGroup(array('B_NAME', 'B_GROESSE', 'B_GEWAESSER_ART', 'B_ZUGANG', 'B_BEK_ART', 'B_TEXT'), 'brutstaette', array('legend' => 'Daten zur Brutstaette')); $pass = $this->getDisplayGroup('brutstaette'); $pass->setDecorators(array('FormElements', 'Fieldset', array('HtmlTag', array('style' => 'float:right')))); $this->addDisplayGroup(array('senden'), 'submitbutton', array('legend' => 'Daten Abschicken')); $pass = $this->getDisplayGroup('submitbutton'); $pass->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'closeOnly' => true, 'style' => 'float:left')))); $this->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'style' => 'width:98%')), 'Form')); }
/** * 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; }
public function setLabel($label) { $this->setAttrib('label', $label); return parent::setLabel($label); }
public function testRenderCanReplaceContent() { $callback = 'Zend_Form_Decorator_CallbackTest_TestCallback'; $element = new Zend_Form_Element('foobar'); $element->setLabel('Label Me'); $this->decorator->setOptions(array('callback' => $callback, 'placement' => false))->setElement($element); $content = $this->decorator->render('foo bar'); $this->assertNotContains('foo bar', $content, $content); $this->assertContains($element->getName(), $content); $this->assertContains($element->getLabel(), $content); }
/** * * @param Zend_Form_Element|string $element * @return Zend_Form_Element */ public function replaceElement($element) { $name = $element->getName(); $previousElement = $this->getElement($name); if ($previousElement) { $label = $this->getElement($name)->getLabel(); $element->setLabel($label); } $this->addElement($element); return $this; }