function indexAction() { $form = new Zend_Form(); $form->setAction($_SERVER['REQUEST_URI'])->setMethod('post')->setAttrib("id", "formPublish"); $jobs_per_categ = $form->createElement('text', 'jobs_per_categ')->setLabel('Job title:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->addValidator('notEmpty')->setDescription('Ex: "Flash Designer" or "ASP.NET Programmer"')->setRequired(true); $submit = $form->createElement('submit', 'submit')->setLabel("Set"); $config = Zend_Registry::get("conf"); foreach ($this->textItems as $category => $items) { foreach ($items as $key => $label) { $item = $form->createElement('text', $key)->setLabel($label)->addValidator('notEmpty')->setRequired(true)->setValue($config->{$category}->{$key}); $form->addElement($item); } $form->addDisplayGroup(array_keys($items), $category, array('legend' => ucfirst($category))); } foreach ($this->checkItems as $category => $items) { foreach ($items as $key => $label) { $item = $form->createElement('checkbox', $key)->setLabel($label)->setChecked($config->{$category}->{$key}); } $form->getDisplayGroup($category)->addElement($item); } // Locale select $locales = Zend_Registry::get("Zend_Locale")->getTranslationList('language', 'en'); foreach ($locales as $key => $value) { if (!file_exists("Joobsbox/Languages/{$key}")) { unset($locales[$key]); } } $locale = $form->createElement('select', 'locale')->setMultiOptions($locales)->setLabel($this->view->translate("Language"))->setValue($config->general->locale); $form->getDisplayGroup('general')->addElement($locale); // Timezone select $tzfile = file("config/timezones.ini.php"); $timezones = array(); foreach ($tzfile as $value) { $value = trim($value); $value = str_replace('"', '', $value); $timezones[$value] = $value; } $timezone = $form->createElement('select', 'site_timezone')->setMultiOptions($timezones)->setLabel($this->view->translate("Timezone"))->setValue($config->general->timezone); $form->getDisplayGroup('general')->addElement($timezone); $form->addElement($submit); $this->form = $form; $this->view->form = $form->render(); if ($this->getRequest()->isPost()) { $this->validateForm(); return; } $this->view->form = $this->form->render(); }
public function testAddElementToDisplayGroupByElementInstance() { $element = new Zend_Form_Element_Text('foo'); $this->form->addElement($element); $this->form->addDisplayGroup(array($element), 'bar'); $this->assertNotNull($this->form->getDisplayGroup('bar')->getElement('foo')); }
public function makeOptionCheckbox(Zend_Form $form, $elements, $label = 'Options', $displayGroupName = 'options') { foreach ($elements as $element) { $form->getElement($element)->setAttrib('noFormItem', true); } $form->addDisplayGroup($elements, $displayGroupName); $form->getDisplayGroup($displayGroupName)->setAttrib('class', 'form-checkbox')->setAttrib('formItem', 'true')->setLegend($label); return $form; }
/** * @group ZF-3254 */ public function testAddingDisplayGroupShouldPassOptions() { $this->testCanAddAndRetrieveMultipleElements(); $this->form->addDisplayGroup(array('bar', 'bat'), 'barbat', array('disableLoadDefaultDecorators' => true)); $group = $this->form->getDisplayGroup('barbat'); $this->assertTrue($group instanceof Zend_Form_DisplayGroup); $decorators = $group->getDecorators(); $this->assertTrue(is_array($decorators)); $this->assertTrue(empty($decorators)); }
/** * 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')); }
/** * @group ZF-10491 * @group ZF-10734 * @group ZF-10731 */ public function testAddElementToDisplayGroupByElementInstance() { $element = new Zend_Form_Element_Text('foo'); $elementTwo = new Zend_Form_Element_Text('baz-----'); $this->form->addElements(array($element, $elementTwo)); $this->form->addDisplayGroup(array($element, $elementTwo), 'bar'); $displayGroup = $this->form->getDisplayGroup('bar'); $this->assertNotNull($displayGroup->getElement('foo')); $this->assertNotNull($displayGroup->getElement('baz')); // clear display groups and elements $this->form->clearDisplayGroups()->clearElements(); $this->form->addDisplayGroup(array($element, $elementTwo), 'bar'); $displayGroup = $this->form->getDisplayGroup('bar'); $this->assertNotNull($displayGroup->getElement('foo')); $this->assertNotNull($displayGroup->getElement('baz')); }
public function form($values = array()) { $config = Zend_Registry::get('config'); $form = new Zend_Form(); $form->setAttrib('id', 'eventForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $workshop = new Workshop(); $where = $workshop->getAdapter()->quoteInto('status = ?', 'enabled'); $workshops = $workshop->fetchAll($where, 'title'); $workshopList = array(); foreach ($workshops as $w) { $workshopList[$w->workshopId] = $w->title; } $workshopElement = $form->createElement('select', 'workshop', array('label' => 'Workshop:')); $workshopElement->setMultiOptions($workshopList)->setValue(isset($values['workshopId']) ? $values['workshopId'] : ''); $location = new Location(); $where = $location->getAdapter()->quoteInto('status = ?', 'enabled'); $locations = $location->fetchAll($where, 'name'); $locationList = array(); $locationCapacity = array(); foreach ($locations as $l) { $locationList[$l->locationId] = $l->name; $locationCapacity['loc_' . $l->locationId] = $l->capacity; } $locationIds = array_keys($locationList); // add the location capacities to the page in js so we can process it as a json object for the "live" max size changing with location selection Zend_Layout::getMvcInstance()->getView()->headScript()->appendScript('var locationCapacitiesString = ' . Zend_Json::encode($locationCapacity) . ';'); $locationElement = $form->createElement('select', 'location', array('label' => 'Location:')); $locationElement->setMultiOptions($locationList)->setValue(isset($values['locationId']) ? $values['locationId'] : $locationCapacity['loc_' . $locationIds[0]]); $date = $form->createElement('text', 'date', array('label' => 'Date:')); $date->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '128')->setAttrib('style', 'width: 200px')->setValue(isset($values['date']) ? strftime('%A, %B %e, %Y', strtotime($values['date'])) : ''); $password = $form->createElement('text', 'password', array('label' => 'Event Password:'******'StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '100')->setValue(isset($values['password']) ? $values['password'] : ''); // add the start time selector $startTimeSub = new Zend_Form_SubForm(); $startTimeSub->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')))); $startTimeSub->setAttrib('class', 'sub'); $startTimeHour = $startTimeSub->createElement('select', 'hour', array('label' => 'Start Time:')); for ($i = 1; $i <= 12; $i++) { $startTimeHour->addMultiOption($i, $i); } $startTimeHour->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')), array('Label'))); $startTimeHour->setValue(isset($values['startTime']) ? date('g', strtotime($values['startTime'])) : date('g')); $startTimeMinute = $startTimeSub->createElement('select', 'minute'); for ($i = 0; $i < 60; $i += 5) { $startTimeMinute->addMultiOption(str_pad($i, 2, '0', STR_PAD_LEFT), str_pad($i, 2, '0', STR_PAD_LEFT)); } $startTimeMinute->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $startTimeMinute->setValue(isset($values['startTime']) ? date('i', strtotime($values['startTime'])) : date('i')); $startTimeMeridian = $startTimeSub->createElement('select', 'meridian'); $startTimeMeridian->addMultiOption('am', 'AM')->addMultiOption('pm', 'PM')->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $startTimeMeridian->setValue(isset($values['startTime']) ? date('a', strtotime($values['startTime'])) : date('a')); $startTimeSub->addElements(array($startTimeHour, $startTimeMinute, $startTimeMeridian)); // add the end time selector $endTimeSub = new Zend_Form_SubForm(); $endTimeSub->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')))); $endTimeSub->setAttrib('class', 'sub'); $endTimeHour = $endTimeSub->createElement('select', 'hour', array('label' => 'End Time:')); for ($i = 1; $i <= 12; $i++) { $endTimeHour->addMultiOption($i, $i); } $endTimeHour->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')), array('Label'))); $endTimeHour->setValue(isset($values['endTime']) ? date('g', strtotime($values['endTime'])) : date('g')); $endTimeMinute = $endTimeSub->createElement('select', 'minute'); for ($i = 0; $i < 60; $i += 5) { $endTimeMinute->addMultiOption(str_pad($i, 2, '0', STR_PAD_LEFT), str_pad($i, 2, '0', STR_PAD_LEFT)); } $endTimeMinute->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $endTimeMinute->setValue(isset($values['endTime']) ? date('i', strtotime($values['endTime'])) : date('i')); $endTimeMeridian = $endTimeSub->createElement('select', 'meridian'); $endTimeMeridian->addMultiOption('am', 'AM')->addMultiOption('pm', 'PM')->setDecorators(array(array('ViewHelper', array('helper' => 'formSelect')))); $endTimeMeridian->setValue(isset($values['endTime']) ? date('a', strtotime($values['endTime'])) : date('a')); $endTimeSub->addElements(array($endTimeHour, $endTimeMinute, $endTimeMeridian)); // get all the users available for the instructor list $otAccount = new Ot_Account(); $accounts = $otAccount->fetchAll(null, array('lastName', 'firstName'))->toArray(); $instructorList = array(); foreach ($accounts as $a) { $instructorList[$a['accountId']] = $a['lastName'] . ", " . $a['firstName']; } $instructorElement = $form->createElement('multiselect', 'instructors', array('label' => 'Instructor(s):')); $instructorElement->setMultiOptions($instructorList)->setAttrib('size', 10)->setValue(isset($values['instructorIds']) ? $values['instructorIds'] : ''); $minSize = $form->createElement('text', 'minSize', array('label' => 'Min Size:')); $minSize->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setAttrib('style', 'width: 50px;')->setValue(isset($values['minSize']) ? $values['minSize'] : $config->user->defaultMinWorkshopSize->val); $maxSize = $form->createElement('text', 'maxSize', array('label' => 'Max Size:')); $maxSize->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setAttrib('style', 'width: 50px;')->setValue(isset($values['maxSize']) ? $values['maxSize'] : $locationElement->getValue()); $waitlistSize = $form->createElement('text', 'waitlistSize', array('label' => 'Waitlist Size:')); $waitlistSize->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setAttrib('style', 'width: 50px;')->setValue(isset($values['waitlistSize']) ? $values['waitlistSize'] : $config->user->defaultWorkshopWaitlistSize->val); $evaluationType = $form->createElement('select', 'evaluationType', array('label' => 'Evaluation Type:')); $evaluationType->setMultiOptions(array('default' => 'Default', 'google' => 'Google Form'))->setRequired(true)->setValue(isset($values['evaluationType']) ? $values['evaluationType'] : 'default'); $formKey = $form->createElement('textarea', 'formKey', array('label' => 'Google Form Question Key:')); $formKey->setAttribs(array('cols' => '10', 'rows' => '5', 'style' => 'width : 250px;'))->addDecorators(array('ViewHelper', 'Errors', 'HtmlTag', array('Label', array('tag' => 'span')), array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'id' => 'formKey', 'class' => 'elm'))))->setValue(isset($values['formKey']) ? $values['formKey'] : ''); $answerKey = $form->createElement('textarea', 'answerKey', array('label' => 'Google Form Answer Key:')); $answerKey->addFilter('StringTrim')->addFilter('StripTags')->setAttribs(array('cols' => '10', 'rows' => '3', 'style' => 'width : 250px;'))->addDecorators(array('ViewHelper', 'Errors', 'HtmlTag', array('Label', array('tag' => 'span')), array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'id' => 'answerKey', 'class' => 'elm'))))->setValue(isset($values['answerKey']) ? $values['answerKey'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($workshopElement, $locationElement, $password, $date, $evaluationType))->addSubForms(array('startTime' => $startTimeSub, 'endTime' => $endTimeSub))->addElements(array($minSize, $maxSize, $waitlistSize, $instructorElement)); $form->addDisplayGroup(array('instructors'), 'instructors-group', array('legend' => 'Instructors')); $form->addDisplayGroup(array('workshop', 'password', 'location', 'minSize', 'maxSize', 'waitlistSize'), 'generalInformation', array('legend' => 'General Information')); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); $form->addElements(array($evaluationType, $formKey, $answerKey)); $form->addDisplayGroup(array('evaluationType', 'formKey', 'answerKey'), 'evaluationTypes', array('legend' => 'Evaluations')); $form->addDisplayGroup(array('submitButton', 'cancel'), 'buttons'); $form->setDisplayGroupDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'widget-content')), array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div', 'class' => array('widget-footer', 'ui-corner-bottom'), 'placement' => Zend_Form_Decorator_Abstract::APPEND)), array('FieldSet', array('class' => 'formField')))); $buttons = $form->getDisplayGroup('buttons'); $buttons->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'style' => 'clear : both;')))); if (isset($values['eventId'])) { $eventId = $form->createElement('hidden', 'eventId'); $eventId->setValue($values['eventId']); $eventId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($eventId); } return $form; }
/** * 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'))); }