Exemple #1
1
 /**
  * Hook for node form - if type is Filemanager Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     if (!Zend_Controller_Front::getInstance()->getRequest()->isXmlHttpRequest() && $item->type == "filemanager_file") {
         // Add Filemanager fields
         $form->setAttrib('enctype', 'multipart/form-data');
         $file = new Zend_Form_Element_File('filemanager_file');
         $file->setLabel("Select file")->setDestination(ZfApplication::$_data_path . DIRECTORY_SEPARATOR . "files")->setRequired(false);
         $form->addElement($file);
         $fields[] = 'filemanager_file';
         if ($item->id > 0) {
             // Fetch Filemanager object
             $factory = new Filemanager_File_Factory();
             $file_item = $factory->find($item->id)->current();
             if ($file_item) {
                 $existing = new Zend_Form_Element_Image('filemanager_image');
                 if (substr($file_item->mimetype, 0, 5) == "image") {
                     $imageid = $file_item->nid;
                 } else {
                     $imageid = 0;
                 }
                 $urlOptions = array('module' => 'filemanager', 'controller' => 'file', 'action' => 'show', 'id' => $imageid);
                 $existing->setImage(Zend_Controller_Front::getInstance()->getRouter()->assemble($urlOptions, 'default'));
                 $fields[] = 'filemanager_image';
             }
         }
         $options = array('legend' => Zoo::_("File upload"));
         $form->addDisplayGroup($fields, 'filemanager_fileupload', $options);
     } else {
         // Add content node image selector
     }
 }
Exemple #2
0
 /**
  * Hook for node form - if type is Guestbook Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     if ($item->type == "guestbook_entry") {
         // Add guestbook fields
         $name = new Zend_Form_Element_Text('guestbook_name', array('size' => 35));
         $name->setLabel('Name');
         $name->setRequired(true);
         $email = new Zend_Form_Element_Text('guestbook_email', array('size' => 35));
         $email->setLabel('Email');
         $email->setRequired(true)->addValidator(new Zend_Validate_StringLength(6))->addValidator(new Zend_Validate_EmailAddress());
         $url = new Zend_Form_Element_Text('guestbook_homepage', array('size' => 35));
         $url->setLabel('Homepage');
         $url->setRequired(false)->addValidator(new Zend_Validate_StringLength(4))->addValidator(new Zend_Validate_Hostname());
         $form->addElements(array($name, $email, $url));
         $options = array('legend' => Zoo::_("Guest information"));
         $form->addDisplayGroup(array('guestbook_name', 'guestbook_email', 'guestbook_homepage'), 'guestbook_add', $options);
         if ($item->id > 0) {
             // Fetch guestbook object
             $factory = new Guestbook_Node_Factory();
             $guestbook = $factory->find($item->id)->current();
             if (!$guestbook) {
                 $guestbook = $factory->createRow();
             }
             $values = $guestbook->toArray();
             $populate = array();
             foreach ($values as $key => $value) {
                 $populate['guestbook_' . $key] = $value;
             }
             $form->populate($populate);
         }
     }
 }
 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'));
 }
Exemple #4
0
 /**
  * Hook for node form, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     $content_type = Zoo::getService('content')->getType($item->type);
     if ($content_type->has_parent_url == 0) {
         $path = new Zend_Form_Element_Text('rewrite_path', array('size' => 65));
         $path->setLabel('URL');
         $form->addElement($path);
         $options = array('legend' => Zoo::_("URL Rewriting"));
         $form->addDisplayGroup(array('rewrite_path'), 'rewrite_path_options', $options);
         if ($item->id > 0) {
             $factory = new Rewrite_Path_Factory();
             $path = $factory->find($item->id)->current();
             if ($path) {
                 $form->populate(array('rewrite_path' => $path->path));
             } else {
                 // Find parent's path
                 if ($item->pid && ($path = $factory->find($item->pid)->current())) {
                     $form->populate(array('rewrite_path' => $path->path . "/" . $item->id));
                 } else {
                     $form->populate(array('rewrite_path' => $item->url()));
                 }
             }
         }
     }
 }
Exemple #5
0
 public function getForm()
 {
     $form = new Zend_Form();
     $form->addElement('text', 'foo')->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat');
     $subForm = new Zend_Form_SubForm();
     $subForm->addElement('text', 'foo')->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat');
     $form->addDisplayGroup(array('foo', 'bar'), 'foobar')->addSubForm($subForm, 'sub')->setView(new Zend_View());
     return $form;
 }
 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;
 }
Exemple #7
0
 /**
  * Hook for node form - if type is Estate Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     $title = new Zend_Form_Element_Text('title', array('class' => 'content_title'));
     $title->setLabel('Title');
     $title->setRequired(true)->addValidator(new Zend_Validate_StringLength(2, 255));
     $content = new Zoo_Form_Element_Wysiwyg('content');
     $content->setRequired(false)->setLabel('Content')->setAttrib('cols', 50);
     $form->addElements(array($title, $content));
     $form->addDisplayGroup(array('title', 'content'), 'content_add', array('legend' => Zoo::_('Content')));
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $identity = Zend_Auth::getInstance()->getIdentity();
         $uid = $identity->id;
     } else {
         $uid = 0;
     }
     $filters = Zoo::getService('filter')->getFiltersByUser($uid);
     if ($filters && $filters->count() > 0) {
         foreach ($filters as $filter) {
             $options = array();
             if (!$filter->optional) {
                 $options = array('disabled' => 'disabled', 'value' => 1);
             } elseif ($item->id == 0) {
                 $options['value'] = $filter->default;
             }
             $ele = new Zend_Form_Element_Checkbox("filter_" . $filter->name, $options);
             $ele->setLabel($filter->name);
             $form->addElement($ele);
             $elements[] = "filter_" . $filter->name;
             $userfilters[$filter->id] = $filter;
         }
         $options = array('legend' => Zoo::_("Filters"));
         $form->addDisplayGroup($elements, 'filter_set', $options);
         if ($item->id > 0) {
             // Fetch set filters
             $filters = Zoo::getService('content')->getFilters($item);
             $populate = array();
             foreach ($filters as $filter) {
                 $populate['filter_' . $userfilters[$filter->filter_id]->name] = 1;
             }
             $form->populate($populate);
         }
     }
 }
 /**
  * @see Zend_Form::addDisplayGroup
  * 
  * @param array $elements
  * @param string $name
  * @param array|Zend_Config $options
  */
 public function addDisplayGroup(array $elements, $name = null, $options = null)
 {
     parent::addDisplayGroup($elements, $name, $options);
     if ($name != null && $name !== 'form-group-actions') {
         $displayGroup = $this->getDisplayGroup($name);
         if ($displayGroup instanceof Zend_Form_DisplayGroup) {
             $displayGroup->removeDecorator('DtDdWrapper');
             $displayGroup->removeDecorator('HtmlTag');
         }
     }
     return $this;
 }
Exemple #9
0
 public function testCanSetDisplayGroupPrefixPath()
 {
     $this->setupDisplayGroups();
     $this->form->addDisplayGroupPrefixPath('Zend_Foo', 'Zend/Foo/');
     $this->form->addDisplayGroup(array('test1', 'test2'), 'testgroup');
     foreach ($this->form->getDisplayGroups() as $group) {
         $loader = $group->getPluginLoader();
         $paths = $loader->getPaths('Zend_Foo');
         $this->assertFalse(empty($paths));
         $this->assertContains('Foo', $paths[0]);
     }
 }
 /**
  * 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'));
 }
Exemple #11
0
 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();
 }
Exemple #12
0
 /**
  * @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'));
 }
 /**
  * The default action - show the home page
  */
 public function indexAction()
 {
     $this->view->messages = $this->_flashMessenger->getMessages();
     $loginForm = new Zend_Form();
     $unField = new Zend_Form_Element_Text('un');
     $unField->setLabel('User Name');
     $pwField = new Zend_Form_Element_Password('pw');
     $pwField->setLabel('Password');
     $loginForm->addElement($unField);
     $loginForm->addElement($pwField);
     $loginForm->addDisplayGroup(array('un', 'pw'), 'authGroup')->getDisplayGroup('authGroup')->setLegend('Authentication');
     //view specific form additions
     //TODO: not sure if $_SERVER['HTTP_HOST'] is dependable enough to use in this case .. XSS vulnerability
     //TODO: programmatically determine http/https
     $loginForm->setAction('http://' . $_SERVER['HTTP_HOST'] . $this->getFrontController()->getBaseUrl() . $this->_helper->url('authenticate'));
     $loginForm->addElement('submit', 'login');
     $this->view->loginForm = $loginForm;
 }
Exemple #14
0
 /**
  * Hook for node form - if type is Estate Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     if ($item->type == "estate_node") {
         // Add estate fields
         $price = new Zend_Form_Element_Text('estate_price', array('size' => 10));
         $price->setLabel('Price');
         $price->setRequired(true)->addValidator(new Zend_Validate_Int());
         $area = new Zend_Form_Element_Text('estate_area', array('size' => 5));
         $area->setLabel('Area');
         $area->setRequired(true)->addValidator(new Zend_Validate_StringLength(1, 5))->addValidator(new Zend_Validate_Int());
         $rooms = new Zend_Form_Element_Text('estate_rooms', array('size' => 5));
         $rooms->setLabel('Rooms');
         $rooms->setRequired(true)->addValidator(new Zend_Validate_StringLength(1, 5))->addValidator(new Zend_Validate_Int());
         $floors = new Zend_Form_Element_Select('estate_floors');
         $floors->setLabel('Floors');
         $floors->addMultiOptions(array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '>5'));
         $year = new Zend_Form_Element_Text('estate_year');
         $year->setLabel('Built Year');
         $year->setRequired(true)->addValidator(new Zend_Validate_GreaterThan(1500))->addValidator(new Zend_Validate_Int());
         $ground = new Zend_Form_Element_Text('estate_ground');
         $ground->setLabel('Ground area');
         $ground->setRequired(true)->addValidator(new Zend_Validate_Int());
         $form->addElements(array($price, $area, $rooms, $floors, $year, $ground));
         $options = array('legend' => Zoo::_("Real estate information"));
         $form->addDisplayGroup(array('estate_price', 'estate_area', 'estate_rooms', 'estate_floors', 'estate_year', 'estate_ground'), 'estate_add', $options);
         if ($item->id > 0) {
             // Fetch estate object
             $factory = new Estate_Node_Factory();
             $estate = $factory->find($item->id)->current();
             if (!$estate) {
                 $estate = $factory->createRow();
             }
             $values = $estate->toArray();
             $populate = array();
             foreach ($values as $key => $value) {
                 $populate['estate_' . $key] = $value;
             }
             $form->populate($populate);
         }
     }
 }
Exemple #15
0
 /**
  * Get registration form for a new user
  *
  * @return Zend_Form
  */
 function getRegistrationForm()
 {
     $form = new Zend_Form();
     $form->setAction("/register")->setMethod('post');
     $username = new Zend_Form_Element_Text('username');
     $username->setLabel('Username');
     $username->setRequired(true)->addValidator(new Zend_Validate_StringLength(2, 255));
     $password = new Zend_Form_Element_Password('password');
     $password->setRequired(true)->setLabel('Password');
     $submit = new Zend_Form_Element_Submit('save');
     $submit->setLabel('Register');
     $form->addElements(array($username, $password));
     $form->addDisplayGroup(array('username', 'password'), 'user_register', array('legend' => Zoo::_('Register user')));
     try {
         Zoo::getService("hook")->trigger("User", "Registerform", $form);
     } catch (Zoo_Exception_Service $e) {
         // Hook service not available - log? Better not, some people may live happily without a hook service
     }
     $form->addElement($submit);
     return $form;
 }
 public static function commentsForm($pageId)
 {
     $db = Zend_Registry::get('db');
     $translator = Zend_Registry::get('Zend_Translate');
     $curRole = Zend_Registry::get('currentRole');
     $stars = array('', '', '', '', '');
     //making 5 stars for rating
     //check if already this user has rated this page
     $ip = $_SERVER['REMOTE_ADDR'];
     $checkAlreadyRated = $db->fetchAll("SELECT count(id) as ratings FROM comments_ratings WHERE commentatorIp = ? AND pageId = ?", array($ip, $pageId));
     $alreadyRated = $checkAlreadyRated[0]['ratings'];
     $form = new Zend_Form(array('method' => 'post', 'action' => NetActionController::$host . "comments/index/pid/" . $pageId, 'elements' => array('star0' => array('radio', array('required' => false, 'class' => 'star', 'label' => $translator->_('Rate'), 'multioptions' => $stars)), 'commentatorName' => array('text', array('required' => false, 'label' => $translator->_('Name'))), 'commentatorEmail' => array('text', array('required' => true, 'label' => $translator->_('Email'))), 'comment' => array('textarea', array('required' => true, 'label' => $translator->_('Add a comment'))), 'submit' => array('submit', array('label' => $translator->_('Submit'), 'order' => 100)))));
     // Using both captcha and captchaOptions:
     $elementCaptcha = new Zend_Form_Element_Captcha('captchaComments', array('label' => $translator->_("Please verify you're a human"), 'captcha' => 'Figlet', 'captchaOptions' => array('captcha' => 'Figlet', 'wordLen' => 6, 'timeout' => 300)));
     $form->addDisplayGroup(array('name', 'comment'), 'comment', array('legend' => $translator->_('Comment')));
     $form->addElement($elementCaptcha);
     if ($alreadyRated > 0) {
         $form->removeElement('star0');
     }
     if ($curRole != "guest") {
         return $form;
     } else {
         return $translator->_('You have to be logged in to post comments');
     }
 }
Exemple #17
0
 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;
 }
 /**
  * Explicitly removes and re-adds elements to the provided form to
  * ensure that the form re-builds the element order.
  *
  * Due to a bug this is required if the order of an element is
  * changed after the internal form index was created:
  * {@link http://framework.zend.com/issues/browse/ZF-9946}
  *
  * @param Zend_Form $form
  * @param array(Zend_Form_Element|Zend_Form|Zend_Form_DisplayGroup) $elements
  */
 protected function reAssignElements(Zend_Form $form, array $elements)
 {
     $elementsByType = $this->categorizeElements($elements);
     foreach ($elementsByType['elements'] as $element) {
         /* @var $element Zend_Form_Element */
         $form->removeElement($element->getName());
         $form->addElement($element);
     }
     foreach ($elementsByType['subForms'] as $subForm) {
         /* @var $subForm Zend_Form */
         $form->removeSubForm($subForm->getName());
         $form->addSubForm($subForm, $subForm->getName());
     }
     foreach ($elementsByType['displayGroups'] as $displayGroup) {
         /* @var $displayGroup Zend_Form_DisplayGroup */
         $form->removeDisplayGroup($displayGroup->getName());
         $form->addDisplayGroup($displayGroup->getElements(), $displayGroup->getName());
     }
 }
 private function _addLanguageForm($languageCodes)
 {
     $form = new Zend_Form(array('method' => 'post', 'id' => 'adminAddLanguageForm', 'action' => $this->_host . 'creator/add-language', 'elements' => array('id' => array('select', array('required' => true, 'label' => '', 'style' => 'width:100%;', 'multioptions' => $languageCodes)), 'submit' => array('submit', array('label' => 'Add', 'order' => 100, 'value' => 'Submit')))));
     $form->addDisplayGroup(array('id'), 'add_lang', array('legend' => $this->translator->_('Add new Language')));
     return $form;
 }
 private function buildForm($action)
 {
     $gform = new Zend_Form();
     $gform->setAction($action)->setMethod("POST");
     //Temp ID
     $gform->addElement('hidden', 'tmp_id', array());
     $gform->addElement('text', 'name', array("label" => "Group Name", "required" => true));
     $gform->addElement('textarea', 'description', array("label" => "Description", "rows" => 5));
     $gform->addElement('file', 'logo', array("label" => "Logo"));
     $gform->addElement('text', 'url', array("label" => "Site"));
     $gform->addElement('hidden', 'area_coords', array());
     $gform->addElement('hidden', 'user_responsible', array());
     $gform->addElement('hidden', 'admins', array());
     //Get Users
     $users = Doctrine_Query::create()->from('User')->orderBy('name')->execute();
     foreach ($users as $user) {
         $aUsers[$user->id] = $user->name;
     }
     $gform->addElement('select', 'admins_add', array("label" => "Group Manager(s)", "multiOptions" => $aUsers));
     $gform->addElement('text', 'scope', array("label" => "Verbose area location"));
     //get AtivityTypeList
     $actvTypes = Doctrine_Query::create()->from('ActivityType')->orderBy("weight")->execute();
     foreach ($actvTypes as $atype) {
         $gform->addElement('text', "atype_" . $atype->atype, array("label" => $atype->name));
         $atypes[] = "atype_" . $atype->atype;
     }
     $gform->addElement('submit', 'submit', array("label" => "Register"));
     $gform->addDisplayGroup($atypes, "actv");
     $gform->addDisplayGroup(array('name', 'logo', 'url', 'description'), 'gpi');
     $gform->addDisplayGroup(array('user_responsible', 'admins'), 'mgi');
     $gform->addDisplayGroup(array('scope', 'venues'), 'lci');
     $this->view->assign("form", $gform);
     $this->gForm = $gform;
     //Venue icons
     $files = scandir('../public/images/admin/map_icons/');
     foreach ($files as $icon) {
         if ($icon != "." && $icon != ".." && strpos($icon, "_s.") === false) {
             $icons[basename($icon)] = "<img src='images/admin/map_icons/" . basename($icon) . "' />";
         }
     }
     //Venue Form
     $vForm = new Zend_Form();
     $vForm->setAttrib("id", "vn_form")->setMethod("POST")->setAction("")->setName("venue_form");
     $vForm->addElement('text', 'vn_name', array('label' => "Venue Name", "require" => true));
     $vForm->addElement('textarea', 'vn_address', array('label' => "Address", "require" => true, "rows" => 4));
     $vForm->addElement('textarea', 'vn_description', array('label' => "Description", "rows" => 3));
     $vForm->addElement('radio', 'vn_icon', array('label' => "Icon", "multiOptions" => $icons, "escape" => false, "separator" => "  "));
     $vForm->addElement('hidden', 'vn_coords', array());
     $this->view->assign("vForm", $vForm);
     $this->vForm = $vForm;
 }
 protected function _getFormStep2()
 {
     $form = new Zend_Form();
     $users = $this->_getUserNames();
     $applications = $this->_getApplications();
     $usersCount = count($users);
     for ($i = 0; $i < $usersCount; $i++) {
         $form->addElement('hidden', 'name' . $i, array('value' => $users[$i]));
         $form->addElement('text', 'efficiency' . $i, array('label' => 'Efficiency', 'validators' => array('Int', new Zend_Validate_Between(array('min' => 0, 'max' => 10))), 'description' => 'Default value is ' . self::DEFAULT_EFFICIENCY));
         $form->addElement('text', 'focusFactor' . $i, array('label' => 'Focus Factor', 'validators' => array('Int', new Zend_Validate_Between(array('min' => 0, 'max' => 100))), 'description' => 'Default value is ' . self::DEFAULT_FOCUS_FACTOR));
         $form->addElement('multiCheckbox', 'applications' . $i, array('label' => 'Main Applications', 'required' => true, 'multiOptions' => $this->_prepareApplicationsForCheckbox($applications)));
         $form->addDisplayGroup(array('name' . $i, 'efficiency' . $i, 'focusFactor' . $i, 'applications' . $i), 'userGroup' . $i, array('legend' => $users[$i]));
     }
     $form->addElement('hidden', 'applicationsList', array('value' => json_encode($applications)));
     $form->addElement('hidden', 'usersCount', array('value' => $usersCount));
     $form->addElement('hidden', 'accountKey', array('value' => $this->getRequest()->getPost('accountKey')));
     $form->addElement('hidden', 'startDate', array('value' => $this->getRequest()->getPost('startDate')));
     $form->addElement('hidden', 'endDate', array('value' => $this->getRequest()->getPost('endDate')));
     $form->addElement('hidden', 'step', array('value' => 3));
     $form->addElement('submit', 'submit', array('label' => 'Submit'));
     return $form;
 }
Exemple #22
0
 /**
  * @group ZF-11729
  */
 public function testDashSeparatedElementsInDisplayGroupsShouldNotRenderOutsideDisplayGroup()
 {
     $form = new Zend_Form();
     $form->addElement('text', 'random-element-name', array('label' => 'This is weird', 'value' => 'think its a bug'));
     $form->addDisplayGroup(array('random-element-name'), 'foobar', array('legend' => 'foobar'));
     $html = $form->render($this->getView());
     $count = substr_count($html, 'randomelementname-element');
     $this->assertEquals(1, $count, $html);
 }
 /**
  * Perform some actions on the form, right before it is displayed but already populated
  *
  * Here we add the table display to the form.
  *
  * @param \Zend_Form $form
  * @param bool      $isNew
  * @return \Zend_Form
  */
 public function beforeFormDisplay($form, $isNew)
 {
     if ($this->useTabbedForms || $form instanceof \Gems_Form_TableForm) {
         //If needed, add a row of link buttons to the bottom of the form
         if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
             $linkContainer = \MUtil_Html::create()->div(array('class' => 'element-container-labelless'));
             $linkContainer[] = $links;
             $element = $form->createElement('html', 'formLinks');
             $element->setValue($linkContainer);
             $element->setOrder(999);
             if ($form instanceof \Gems_TabForm) {
                 $form->resetContext();
             }
             $form->addElement($element);
             $form->addDisplayGroup(array('formLinks'), 'form_buttons');
         }
     } else {
         if (\MUtil_Bootstrap::enabled() !== true) {
             $table = new \MUtil_Html_TableElement(array('class' => 'formTable'));
             $table->setAsFormLayout($form, true, true);
             $table['tbody'][0][0]->class = 'label';
             // Is only one row with formLayout, so all in output fields get class.
             if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
                 $table->tf();
                 // Add empty cell, no label
                 $linksCell = $table->tf($links);
             }
         } elseif ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
             $element = $form->createElement('html', 'menuLinks');
             $element->setValue($links);
             $element->setOrder(999);
             $form->addElement($element);
         }
     }
     return $form;
 }
Exemple #24
0
 /**
  * Возвращает массив объектов Zend_Form мини-форм по типам 
  *
  * @return array
  */
 public function getForms()
 {
     $forms = array();
     foreach ($this->configs as $fieldtype => $template) {
         $form = new Zend_Form($template);
         $form->setElementsBelongTo('fields[]');
         $form->addDisplayGroup(array_keys($template['elements']), 'main', array('legend' => $template['label'], 'class' => 'ui-widget-content'));
         $form->removeDecorator('Form');
         $form->removeDecorator('DtDdWrapper');
         $form->setTranslator($this->translate);
         $forms[$fieldtype] = $form;
     }
     return $forms;
 }
Exemple #25
0
 /**
  * Add a display group
  *
  * Groups named elements for display purposes.
  *
  * If a referenced element does not yet exist in the form, it is omitted.
  *
  * @param  array $elements
  * @param  string $name
  * @param  array|Zend_Config $options
  * @return Zend_Form
  * @throws Zend_Form_Exception if no valid elements provided
  */
 public function addDisplayGroup(array $elements, $name, $options = null)
 {
     // Allow custom decorators, but default to a sensible set
     if (empty($options['decorators'])) {
         $options['decorators'] = array('FormElements', 'Fieldset');
     }
     return parent::addDisplayGroup($elements, $name, $options);
 }
Exemple #26
0
 /**
  * Hook for node form - if type is Filemanager Node, add extra fields
  *
  * @param Zend_Form $form
  * @param array $arguments
  */
 public function nodeForm(Zend_Form &$form, &$arguments)
 {
     $item =& array_shift($arguments);
     if ($item->type == "gallery_node") {
         $bgcolor = new Zoo_Form_Element_ColorPicker('gallery_bgcolor');
         $bgcolor->setLabel('Background colour');
         $config = Zoo::getConfig('gallery', 'module');
         /*
         $topimage = new Zend_Form_Element_Radio('gallery_topimage');
         $topimage->setLabel('Top image');
         $topimage->setOptions(array('escape' => false));
         $topimages = Zoo::getService('content')->getContent(array('parent' => $config->top_image, 
         														  'nodetype' => 'filemanager_file'));
         $topimage->addMultiOption(0, Zoo::_("None"));
         foreach ($topimages as $image) {
         	$topimage->addMultiOption($image->id, $image->title."<br /><img src='".$image->hooks['filemanager_file']->getUrl(200)."' />");
         }
         */
         $topimage = new Zoo_Form_Element_FileBrowser('gallery_topimage');
         $topimage->setLabel('Top image');
         $bgimage = new Zoo_Form_Element_FileBrowser('gallery_bgimage');
         $bgimage->setLabel('Background image');
         $form->addElements(array($bgcolor, $topimage, $bgimage));
         $options = array('legend' => Zoo::_("Gallery extras"));
         $form->addDisplayGroup(array('gallery_bgcolor', 'gallery_topimage', 'gallery_bgimage'), 'gallery_node', $options);
         if ($item->id > 0) {
             // Fetch extra information
             $top_image = Zoo::getService('link')->getLinkedNodes($item, 'top_image');
             $populate['gallery_topimage'] = count($top_image) > 0 ? $top_image[0]->id : 0;
             $bg_image = Zoo::getService('link')->getLinkedNodes($item, 'bg_image');
             $populate['gallery_bgimage'] = count($bg_image) > 0 ? $bg_image[0]->id : 0;
             $factory = new Gallery_Node_Factory();
             $gnode = false;
             // Fetch estate object
             $gnode = $factory->find($item->id)->current();
             if ($gnode) {
                 $populate['gallery_bgcolor'] = $gnode->bgcolor;
             }
             $form->populate($populate);
         }
     }
 }
Exemple #27
0
 public function addFormActions(array $elements)
 {
     return parent::addDisplayGroup($elements, 'form_actions', array('disableLoadDefaultDecorators' => true, 'decorators' => array(array('Actions', array('style' => 'clear:both')))));
 }
 /**
  * @return Zend_Form
  */
 private function getNewByingsForm()
 {
     $form = new Zend_Form();
     $form->setAction($this->view->url(array('action' => 'create')));
     for ($i = 0; $i < 10; $i++) {
         $buyingName = new Zend_Form_Element_Text(array('name' => "product{$i}"));
         $buyingName->setLabel('Produkt');
         $buyingPrice = new Zend_Form_Element_Text(array('name' => "price{$i}"));
         $buyingPrice->setLabel('Preis');
         $buyingPrice->addValidator(new Zend_Validate_Float());
         $form->addElements(array($buyingName, $buyingPrice));
         $form->addDisplayGroup(array("product{$i}", "price{$i}"), "buying{$i}");
     }
     $submit = new Zend_Form_Element_Submit(array('name' => 'submit'));
     $submit->setLabel('Einkäufe eintragen');
     $form->addElement($submit);
     return $form;
 }
 private function __contactForm($formList, $contactId = null)
 {
     $db = Zend_Registry::get('db');
     if (!is_array($formList)) {
         $contactFormName = $formList;
         $formList = $db->fetchAll("SELECT * FROM mod_forms LEFT JOIN mod_forms_fields ON mod_forms.id = mod_forms_fields.form_id WHERE enabled = '1' AND mod_forms.name = ?", array($contactFormName));
     }
     $formId = $formList[0]['form_id'];
     $formIdContact = $formList[0]['contact'];
     //OVO TREBA VRATITI!
     $contactEmail = $db->fetchAll("SELECT email FROM contacts WHERE id = ?", array($formIdContact));
     $to = $contactEmail[0]['email'];
     //$to = "*****@*****.**";
     //$welcomePage = $db->fetchRow("SELECT thank_page FROM contact_forms WHERE id = ?", array($formId));
     $fieldsArray = $formList;
     //print_r($contactEmail);
     if (count($fieldsArray)) {
         foreach ($fieldsArray as $field) {
             $type = $field['type'];
             switch ($type) {
                 case 1:
                     $type = "text";
                     $Height = "15px";
                     $required = 'true';
                     break;
                 case 2:
                     $type = "textarea";
                     $Height = "";
                     $required = 'false';
                     break;
                 case 3:
                     $type = "file";
                     $Height = "20px";
                     $required = 'false';
                     break;
                 case 4:
                     $type = "checkbox";
                     $Height = "15px";
                     $required = 'false';
                     break;
             }
             $translator = Zend_Registry::get('Zend_Translate');
             $elements[strtolower(preg_replace('/ /', '_', $field['name']))] = array($type, array('label' => $translator->_($field['name']), 'required' => $required));
             $displayGroupElements[] = strtolower(preg_replace('/ /', '_', $field['name']));
         }
         // Using both captcha and captchaOptions:
         $elementCaptcha = new Zend_Form_Element_Captcha('captchaContact_' . $formId, array('label' => $translator->_("Please verify you're a human"), 'captcha' => 'Dumb', 'captchaOptions' => array('captcha' => 'Dumb', 'wordLen' => 6, 'timeout' => 300)));
         $recaptcha = new Zend_Service_ReCaptcha('6LdrqMgSAAAAAMNf7hOddRHyWYmEmx9zMFYswaXM', '6LdrqMgSAAAAAFwKXLm9V_7CkJtGqX11O7DJWd4k');
         $elements['submitbut'] = array('submit', array('label' => 'Submit', 'order' => 100));
         $elements['to'] = array('hidden', array('value' => $to));
         $elements['formID'] = array('hidden', array('value' => $formId));
         $elements['rcap'] = new Zend_Captcha_ReCaptcha();
         /*
                     $elements['thank_page'] = array('hidden', array(
                             'value' => $welcomePage['thank_page'],
                             ));
         */
         //print_r($elements);
         $labl = "Submit";
         $form = new Zend_Form(array('id' => 'customForm' . $formId, 'class' => 'contactForm', 'method' => 'post', 'action' => NetActionController::$hostRW . 'forms/', 'elements' => $elements));
         $form->setAttrib('enctype', 'multipart/form-data');
         $form->addDisplayGroup($displayGroupElements, 'contactForm', array('legend' => $translator->_('Contact form')));
         $form->addElement($elementCaptcha);
         //$form->addElement($recaptcha);
         return $form;
     }
 }
 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;
 }