/** * Set form decorators. */ protected function setupForm() { // remove default decorators and add own $this->form->clearDecorators(); $this->form->addDecorator('FormElements'); $this->form->addDecorator('HtmlTag', array('tag' => 'dl', 'id' => $this->form->getId(), 'class' => 'form_view')); }
/** * Set form decorators. basically replacing the default <dl> with a <ul> */ protected function setupForm() { // remove default decorators and add own $this->form->clearDecorators(); $this->form->addDecorator('FormElements'); $this->form->addDecorator('HtmlTag', array('tag' => 'ul')); $this->form->addDecorator('Form'); }
public function addSubForm(Zend_Form $form, $name, $order = null) { $form->loadDefaultDecorators(); $form->removeDecorator('Form'); $form->addDecorator('Fieldset')->addDecorator('DtDdWrapper'); $form->setElementsBelongTo($name); return parent::addSubForm($form, $name, $order); }
public function testCanRetrieveSingleDecoratorRegisteredAsDecoratorObjectUsingShortName() { $this->form->clearDecorators(); $this->assertFalse($this->form->getDecorator('viewHelper')); $decorator = new \Zend\Form\Decorator\ViewHelper(); $this->form->addDecorator($decorator); $test = $this->form->getDecorator('viewHelper'); $this->assertSame($decorator, $test); }
/** * initForm * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected function initForm() { $this->objForm = new Zend_Form(); /** * Use our own PluginLoader */ $objLoader = new PluginLoader(); $objLoader->setPluginLoader($this->objForm->getPluginLoader(PluginLoader::TYPE_FORM_ELEMENT)); $objLoader->setPluginType(PluginLoader::TYPE_FORM_ELEMENT); $this->objForm->setPluginLoader($objLoader, PluginLoader::TYPE_FORM_ELEMENT); /** * clear all decorators */ $this->objForm->clearDecorators(); /** * add standard decorators */ $this->objForm->addDecorator('TabContainer'); $this->objForm->addDecorator('FormElements'); $this->objForm->addDecorator('Form'); /** * add form prefix path */ $this->objForm->addPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * elements prefixes */ $this->objForm->addElementPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * regions prefixes */ $this->objForm->addDisplayGroupPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/'); $this->objForm->setAttrib('id', 'genForm'); $this->objForm->setAttrib('onsubmit', 'return false;'); $this->objForm->addElement('hidden', 'id', array('decorators' => array('Hidden'))); $this->objForm->addElement('text', 'title', array('label' => $this->core->translate->_('title', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text keyfield', 'required' => true)); $this->objForm->addElement('text', 'key', array('label' => $this->core->translate->_('key', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text', 'required' => true)); $this->objForm->addDisplayGroup(array('title', 'key'), 'main-resource'); $this->objForm->getDisplayGroup('main-resource')->setLegend($this->core->translate->_('General_information', false)); $this->objForm->getDisplayGroup('main-resource')->setDecorators(array('FormElements', 'Region')); $arrGroups = array(); $sqlStmt = $this->core->dbh->query("SELECT `id`, `title` FROM `groups` ORDER BY `title`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrGroups[$arrSql['id']] = $arrSql['title']; } $this->objForm->addElement('multiCheckbox', 'groups', array('label' => $this->core->translate->_('groups', false), 'value' => $this->arrGroups, 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrGroups)); $this->objForm->addDisplayGroup(array('groups'), 'groups-group'); $this->objForm->getDisplayGroup('groups-group')->setLegend($this->core->translate->_('Resource_groups', false)); $this->objForm->getDisplayGroup('groups-group')->setDecorators(array('FormElements', 'Region')); }
public function getForm() { $form = new Zend_Form(); $form->setName($this->poClass . "_form"); $schema = $this->schema->getSchema(); foreach ($this->getEditableProperties() as $propertyName => $property) { $methodName = 'get' . ucfirst($propertyName) . 'Element'; if (method_exists($this, $methodName)) { $form->addElement($this->{$methodName}()); continue; } $dbField = $schema[$this->poDef->table]->fields[$property->columnName]; $dbType = $dbField->type; switch ($dbType) { case 'integer': case 'timestamp': case 'boolean': $element = new Zend_Form_Element_Text($propertyName); $element->addValidator('allnum'); $element->addFilter('int'); break; case 'float': case 'decimal': $element = new Zend_Form_Element_Text($propertyName); break; case 'blob': case 'clob': $element = new Zend_Form_Element_Textarea($propertyName); break; case 'text': case 'time': case 'date': default: $element = new Zend_Form_Element_Text($propertyName); break; } if (list($relatedClassName, $relationDef) = $this->isFK($property->columnName)) { $element = new Zend_Form_Element_Select($propertyName); $pos = ezcPersistentSessionInstance::get(); $q = $pos->createFindQuery($relatedClassName); $this->queryHook($q); $list = $pos->find($q, $relatedClassName); $element->options = $list; $element->addFilter('int'); } if (!$this->isNullProperty($property->columnName, $this->poDef->table)) { $element->setRequired(true)->addValidator('NotEmpty'); } $element->setLabel($propertyName); $form->addElement($element); } $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel('Submit'); $form->addElement($submit); $form->clearDecorators(); $form->addDecorator('FormElements')->addDecorator('HtmlTag', array('tag' => '<ul>'))->addDecorator('Form'); $form->setElementDecorators(array(array('ViewHelper'), array('Errors'), array('Description'), array('Label', array('separator' => ' ')), array('HtmlTag', array('tag' => 'li', 'class' => 'element-group')))); // buttons do not need labels $submit->setDecorators(array(array('ViewHelper'), array('Description'), array('HtmlTag', array('tag' => 'li', 'class' => 'submit-group')))); $form->setView(new Zend_View()); return $form; }
/** * Fuegt Anker fuer Positionierung des Formulars im Browser hinzu. * * Durch den Anker springt der Browser nach einem POST zu der gewuenschten Stelle, zum Beispiel dem gerade neu * hinzugefuegten Unterformular. * * @param Zend_Form $subform */ protected function _addAnker($subform) { $subform->addDecorator(array('currentAnker' => 'HtmlTag'), array('tag' => 'a', 'placement' => 'prepend', 'name' => 'current')); }
<?php ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/path/to/zend/library'); require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); $request = new Zend_Controller_Request_Http(); $view = new Zend_View(); /** * Example showing usage of array notation using setElementsBelongTo * on the form level, for shipping/billing addresses. */ $form = new Zend_Form(); $form->setView($view); $form->addDecorator('Description', array('escape' => false, 'placement' => 'PREPEND')); $form->setDescription('<h3>Using setElementsBelongTo</h3>'); $form->setElementsBelongTo('shipping'); $form->addElement('text', 'recipient', array('label' => 'Ship to', 'required' => true)); $form->addElement('text', 'address', array('label' => 'Address', 'required' => true)); $form->addElement('submit', 'submit', array('label' => 'Submit')); if ($request->isPost()) { if ($form->isValid($request->getPost())) { echo 'Order placed, Thank you!'; } else { echo 'You have errors in your form, please check'; } } echo $form->render();
/** * initForm * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected function initForm() { $this->objForm = new Zend_Form(); /** * Use our own PluginLoader */ $objLoader = new PluginLoader(); $objLoader->setPluginLoader($this->objForm->getPluginLoader(PluginLoader::TYPE_FORM_ELEMENT)); $objLoader->setPluginType(PluginLoader::TYPE_FORM_ELEMENT); $this->objForm->setPluginLoader($objLoader, PluginLoader::TYPE_FORM_ELEMENT); /** * clear all decorators */ $this->objForm->clearDecorators(); /** * add standard decorators */ $this->objForm->addDecorator('TabContainer'); $this->objForm->addDecorator('FormElements'); $this->objForm->addDecorator('Form'); /** * add form prefix path */ $this->objForm->addPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * elements prefixes */ $this->objForm->addElementPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * regions prefixes */ $this->objForm->addDisplayGroupPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/'); $arrGroupTypeOptions = array(); $sqlStmt = $this->core->dbh->query("SELECT `id`, `title` FROM `groupTypes`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrGroupTypeOptions[$arrSql['id']] = ucfirst($arrSql['title']); } $this->objForm->setAttrib('id', 'genForm'); $this->objForm->setAttrib('onsubmit', 'return false;'); $this->objForm->addElement('hidden', 'id', array('decorators' => array('Hidden'))); $this->objForm->addElement('text', 'title', array('label' => $this->core->translate->_('title', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text keyfield', 'required' => true)); $this->objForm->addElement('text', 'key', array('label' => $this->core->translate->_('key', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text', 'required' => true)); $this->objForm->addElement('textarea', 'description', array('label' => $this->core->translate->_('description', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text')); $this->objForm->addElement('multiCheckbox', 'groupTypes', array('label' => $this->core->translate->_('groupTypes', false), 'value' => $this->arrGroupTypes, 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrGroupTypeOptions)); $this->objForm->addDisplayGroup(array('title', 'key', 'description', 'groupTypes'), 'main-group', array('columns' => 9)); $this->objForm->getDisplayGroup('main-group')->setLegend($this->core->translate->_('General_information', false)); $this->objForm->getDisplayGroup('main-group')->setDecorators(array('FormElements', 'Region')); $arrPermissionOptions = array(); $sqlStmt = $this->core->dbh->query("SELECT `id`, UCASE(`title`) AS title FROM `permissions`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrPermissionOptions[$arrSql['id']] = $arrSql['title']; } $arrLanguageOptions = array(); $arrLanguageOptions['0'] = $this->core->translate->_('All_languages', false); $sqlStmt = $this->core->dbh->query("SELECT `id`, `title` FROM `languages`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrLanguageOptions[$arrSql['id']] = $arrSql['title']; } $strRegionInstances = ''; $intRegionCounter = 0; /** * create group permisson regions */ foreach ($this->arrPermissions as $arrPermission) { $intRegionCounter++; $this->objForm->addElement('radio', 'language_' . $intRegionCounter, array('label' => $this->core->translate->_('language', false), 'value' => $arrPermission['language'], 'decorators' => array('Input'), 'columns' => 6, 'class' => 'radio', 'MultiOptions' => $arrLanguageOptions)); $this->objForm->addElement('multiCheckbox', 'permissions_' . $intRegionCounter, array('label' => $this->core->translate->_('permissions', false), 'value' => $arrPermission['permissions'], 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrPermissionOptions)); $this->objForm->addDisplayGroup(array('language_' . $intRegionCounter, 'permissions_' . $intRegionCounter), 'Permission_' . $intRegionCounter, array('columns' => 9, 'regionTypeId' => 1, 'collapsable' => 0, 'regionCounter' => $intRegionCounter, 'regionId' => 'Permission', 'regionExt' => $intRegionCounter, 'isMultiply' => true, 'regionTitle' => $this->core->translate->_('Language_specific', false))); $this->objForm->getDisplayGroup('Permission_' . $intRegionCounter)->setLegend($this->core->translate->_('Permissions', false)); $this->objForm->getDisplayGroup('Permission_' . $intRegionCounter)->setDecorators(array('FormElements', 'Region')); $strRegionInstances .= '[' . $intRegionCounter . ']'; } $this->objForm->addElement('radio', 'language_REPLACE_n', array('label' => $this->core->translate->_('language', false), 'decorators' => array('Input'), 'columns' => 6, 'class' => 'radio', 'MultiOptions' => $arrLanguageOptions)); $this->objForm->addElement('multiCheckbox', 'permissions_REPLACE_n', array('label' => $this->core->translate->_('permissions', false), 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrPermissionOptions)); $this->objForm->addDisplayGroup(array('language_REPLACE_n', 'permissions_REPLACE_n'), 'Permission_REPLACE_n', array('columns' => 9, 'regionTypeId' => 1, 'collapsable' => 0, 'regionId' => 'Permission', 'regionExt' => 'REPLACE_n', 'isMultiply' => true, 'isEmptyWidget' => true, 'regionTitle' => $this->core->translate->_('Language_specific', false))); $this->objForm->getDisplayGroup('Permission_REPLACE_n')->setLegend('Rechte'); $this->objForm->getDisplayGroup('Permission_REPLACE_n')->setDecorators(array('FormElements', 'Region')); $this->objForm->addElement('hidden', 'Region_Permission_Instances', array('value' => $strRegionInstances, 'decorators' => array('Hidden'))); $this->objForm->addElement('hidden', 'Region_Permission_Order', array('value' => '', 'decorators' => array('Hidden'))); }