Esempio n. 1
0
 public function setValue($value)
 {
     if (count($this->getMultiOptions()) == 0) {
         $this->setMultiOptions();
     }
     parent::setValue($value);
 }
Esempio n. 2
0
 public function init()
 {
     $this->setName(strtolower(get_class()));
     $this->setMethod("post");
     $oFormName = new Zend_Form_Element_Hidden("form_name");
     $oFormName->setValue(get_class());
     $oFormName->setIgnore(FALSE)->removeDecorator("Label");
     $this->addElement($oFormName);
     $oOnlineChatUserRecipients = new Zend_Form_Element_Multiselect("online_chat_user_recipients");
     $oOnlineChatUserRecipients->setLabel("Konsultanci on-line:");
     $oOnlineChatUserRecipients->setRequired(FALSE);
     $oOnlineChatUserRecipients->setAttrib("class", "multiselect");
     $oOnlineChatUserRecipients->addMultiOptions($this->_aChatUserRecipients);
     $oOnlineChatUserRecipients->setValue($this->_aOnlineChatUserRecipients);
     $this->addElement($oOnlineChatUserRecipients);
     $this->addElement("hash", "csrf_token", array("ignore" => false, "timeout" => 7200));
     $this->getElement("csrf_token")->removeDecorator("Label");
     $oSubmit = $this->createElement("submit", "submit");
     $oSubmit->setLabel("Zapisz");
     $this->addElement($oSubmit);
     $oViewScript = new Zend_Form_Decorator_ViewScript();
     $oViewScript->setViewModule("admin");
     $oViewScript->setViewScript("_forms/_defaultform.phtml");
     $this->clearDecorators();
     $this->setDecorators(array(array($oViewScript)));
     $oElements = $this->getElements();
     foreach ($oElements as $oElement) {
         $oElement->setFilters($this->_aFilters);
         $oElement->removeDecorator("Errors");
     }
 }
Esempio n. 3
0
 public function renderFormElement()
 {
     $elm = new Zend_Form_Element_Multiselect($this->getName(), array('label' => $this->getLabel() . ':'));
     $elm->setDescription($this->getDescription());
     $elm->setMultiOptions($this->getOptions());
     $elm->setValue($this->getValue());
     $elm->setRequired($this->getRequired());
     $elm->setAttrib('style', 'width:300px;height:100px');
     return $elm;
 }
Esempio n. 4
0
 /**
  * @group ZF-11667
  */
 public function testSimilarErrorMessagesForMultiElementAreNotDuplicated()
 {
     $this->element->setConcatJustValuesInErrorMessage(true);
     // create element with 4 checkboxes
     $this->element->setMultiOptions(array('multiOptions' => array(array('key' => 'a', 'value' => 'A'), array('key' => 'b', 'value' => 'B'), array('key' => 'c', 'value' => 'C'), array('key' => 'd', 'value' => 'D'))));
     // check 3 of them
     $this->element->setValue(array('A', 'B', 'D'));
     // later on, fails some validation on submit
     $this->element->addError('some error! %value%');
     $this->assertEquals(array('some error! A; B; D'), $this->element->getMessages());
 }
Esempio n. 5
0
 /**
  * Inserts two selections and buttons to control the elements between them.
  *
  * @param string $name - Define elements id. Important to javascript interaction
  * @param string $label
  * @param array $start_itens
  * @param array $end_itens
  */
 public function setSelectBox($name, $label, $start_itens, $end_itens = false)
 {
     $i18n = Zend_Registry::get("i18n");
     $header = new Zend_Form_Element_Hidden('elementHeader');
     $header->removeDecorator("DtDdWrapper")->addDecorator('HtmlTag', array('tag' => 'div', 'id' => 'selects', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::PREPEND));
     $start_box = new Zend_Form_Element_Multiselect("box");
     $start_box->setLabel($i18n->translate($label))->setMultiOptions($start_itens)->removeDecorator('DtDdWrapper')->setAttrib('id', $name . '_box')->setRegisterInArrayValidator(false);
     $end_box = new Zend_Form_Element_Multiselect("box_add");
     if ($end_itens) {
         $end_box->setMultiOptions($end_itens);
         $end_box->setValue(array_keys($end_itens));
     }
     $end_box->removeDecorator('DtDdWrapper')->removeDecorator('Label')->setAttrib('id', $name . '_box_add')->addDecorator('HtmlTag', array('tag' => 'div', 'id' => 'selects', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND))->setRegisterInArrayValidator(false);
     $add_action = new Zend_Form_Element_Button($i18n->translate('Add'));
     $add_action->removeDecorator("DtDdWrapper")->addDecorator('HtmlTag', array('tag' => 'li'))->setAttrib('id', $name . '_add_bt')->setAttrib('class', 'add_item')->addDecorator('HtmlTag', array('tag' => 'div', 'id' => 'selectActions', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::PREPEND));
     $remove_action = new Zend_Form_Element_Button($i18n->translate('Remove'));
     $remove_action->removeDecorator("DtDdWrapper")->addDecorator('HtmlTag', array('tag' => 'li'))->setAttrib('id', $name . '_remove_bt')->setAttrib('class', 'remove_item')->addDecorator('HtmlTag', array('tag' => 'div', 'id' => 'selectActions', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND));
     $this->addElements(array($header, $start_box, $add_action, $remove_action, $end_box));
 }
Esempio n. 6
0
 function getFormElement($v, $value = '')
 {
     $this->toTpl('hasForm', 1);
     $v = $this->doQoolHook('front_pre_getformelement_element', $v);
     $value = $this->doQoolHook('front_pre_getformelement_value', $value);
     switch ($v['value']) {
         case "editor":
             $this->loadEditorBtns();
             $this->toTpl("loadEditor", 1);
             $this->toTpl("isEditor", 1);
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'editor span12');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "fileinput":
             $element = new Zend_Form_Element_File($v['name']);
             $element->setAttrib('class', 'input-file');
             break;
         case "captcha":
             $element = new Zend_Form_Element_Captcha($v['name'], array('label' => $this->t("Please verify you are a human"), 'captcha' => $config->site->captcha_adapter, 'captchaOptions' => array('captcha' => $config->site->captcha_adapter, 'wordLen' => 6, 'timeout' => 300)));
             return $element;
             break;
         case "multifileinputs":
             $element = new Zend_Form_Element_File($v['name']);
             $element->setAttrib('class', 'input-file');
             $element->setMultiFile(10);
             break;
         case "multifileinput":
             $name = $v['name'] . "[]";
             $element = new Zend_Form_Element_File($name);
             $element->setAttrib('class', 'input-file');
             $element->setAttrib('multiple', 'multiple');
             $element->setMultiFileForQool(1);
             $this->toTpl('filelist', true);
             break;
         case "checkbox":
             $element = new Zend_Form_Element_Checkbox($v['name']);
             $element->setAttrib('class', 'checkbox');
             $element->setValue($value);
             break;
         case "editarea":
             $this->toTpl('editarea', 1);
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'editarea span12');
             $element->setAttrib('id', 'editarea');
             $element->setAttrib('style', 'height:500px');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "password":
             $element = new Zend_Form_Element_Password($v['name']);
             break;
         case "textarea":
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'span9');
             $element->setAttrib('style', 'height:80px');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "hidden":
             $element = new Zend_Form_Element_Hidden($v['name']);
             $element->setValue($value);
             $element->setDecorators(array("ViewHelper"));
             break;
         case "textinput":
             $element = new Zend_Form_Element_Text($v['name']);
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "selectbox":
             $element = new Zend_Form_Element_Select($v['name']);
             if ($v['use_pool'] && method_exists($this, $v['use_pool'])) {
                 if ($v['pool_type'] != '0') {
                     $this->pool_type = $v['pool_type'];
                 }
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($this->{$v}['use_pool']() as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
             }
             break;
         case "multiselectbox":
             $element = new Zend_Form_Element_Multiselect($v['name']);
             if ($v['use_pool'] && method_exists($this, $v['use_pool'])) {
                 if ($v['pool_type'] != '0') {
                     $this->pool_type = $v['pool_type'];
                 }
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($this->{$v}['use_pool']() as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if (is_array($value)) {
                     foreach ($value as $a) {
                         $vals[] = $a['selected_value'];
                     }
                     $element->setValue($vals);
                 }
             }
             break;
         case "treeselectbox":
             $element = new Zend_Form_Element_Select($v['name']);
             if ($v['use_pool'] && method_exists($this, $v['use_pool'])) {
                 if ($v['pool_type'] != '0') {
                     $this->pool_type = $v['pool_type'];
                 }
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
                 //x10 times nested support. Needs fix
                 foreach ($this->{$v}['use_pool']() as $vo) {
                     $element->addMultiOption($vo['id'], $vo['title']);
                     foreach ($vo['kids'] as $a) {
                         $element->addMultiOption($a['id'], "|_" . $a['title']);
                         foreach ($a['kids'] as $b) {
                             $element->addMultiOption($b['id'], "|__" . $b['title']);
                             foreach ($b['kids'] as $c) {
                                 $element->addMultiOption($c['id'], "|___" . $c['title']);
                                 foreach ($c['kids'] as $d) {
                                     $element->addMultiOption($d['id'], "|____" . $d['title']);
                                     foreach ($d['kids'] as $e) {
                                         $element->addMultiOption($e['id'], "|_____" . $e['title']);
                                         foreach ($e['kids'] as $f) {
                                             $element->addMultiOption($f['id'], "|______" . $f['title']);
                                             foreach ($f['kids'] as $g) {
                                                 $element->addMultiOption($g['id'], "|______" . $g['title']);
                                                 foreach ($g['kids'] as $h) {
                                                     $element->addMultiOption($h['id'], "|_______" . $h['title']);
                                                     foreach ($h['kids'] as $i) {
                                                         $element->addMultiOption($i['id'], "|________" . $i['title']);
                                                         foreach ($i['kids'] as $j) {
                                                             $element->addMultiOption($j['id'], "|_________" . $j['title']);
                                                             foreach ($j['kids'] as $l) {
                                                                 $element->addMultiOption($l['id'], "|__________" . $l['title']);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
     }
     if ($v['required']) {
         $element->setRequired(true);
     }
     if ($v['title']) {
         $element->setLabel($v['title']);
     } else {
         $element->setLabel($this->t(ucfirst(str_replace("_", " ", $v['name']))));
     }
     if ($v['attributes']) {
         foreach ($v['attributes'] as $k => $r) {
             $element->setAttrib($k, $r);
         }
     }
     //$element->setDecorators(array("ViewHelper"));
     $element = $this->doQoolHook('front_post_getformelement_object', $element);
     return $element;
 }
Esempio n. 7
0
 /**
  * Accepts an array with parameters and mixed values and returns a Zend Form Element to be used by a Zend Form object
  *
  * @param array $v
  * @param mixed $value
  * @return object
  */
 function getFormElement($v, $value = '')
 {
     $config = $this->config;
     $this->toTpl('hasForm', 1);
     $v = $this->doQoolHook('pre_getformelement_element', $v);
     $value = $this->doQoolHook('pre_getformelement_value', $value);
     switch ($v['value']) {
         case "editor":
             $this->loadEditorBtns();
             $this->toTpl("loadEditor", 1);
             $this->toTpl("isEditor", 1);
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'editor span12');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "rte":
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'cleditor span12');
             $this->toTpl("isRTE", 1);
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "fileinput":
             $element = new Zend_Form_Element_File($v['name']);
             $element->setAttrib('class', 'input-file');
             break;
         case "dropboxchooser":
             $element = new Zend_Form_Element_Dropbox($v['name']);
             $element->setAttrib('style', 'visibility:hidden');
             $element->setAttrib('data-multiselect', true);
             break;
         case "captcha":
             if ($config->site->captcha_adapter == 'ReCaptcha') {
                 //Do whats needed for recaptcha to work with form
             }
             $element = new Zend_Form_Element_Captcha($v['name'], array('label' => $this->t("Please verify you are a human"), 'captcha' => $config->site->captcha_adapter, 'captchaOptions' => array('captcha' => $config->site->captcha_adapter, 'wordLen' => 6, 'timeout' => 300)));
             return $element;
             break;
         case "multifileinputs":
             $element = new Zend_Form_Element_File($v['name']);
             $element->setAttrib('class', 'input-file');
             $element->setMultiFile(10);
             break;
         case "multifileinput":
             $name = $v['name'] . "[]";
             $element = new Zend_Form_Element_File($name);
             $element->setAttrib('class', 'input-file');
             $element->setAttrib('multiple', 'multiple');
             $element->setMultiFileForQool(1);
             $this->toTpl('filelist', true);
             break;
         case "checkbox":
             $element = new Zend_Form_Element_Checkbox($v['name']);
             $element->setAttrib('class', 'checkbox');
             $element->setValue($value);
             break;
         case "editarea":
             $this->toTpl('editarea', 1);
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'editarea span12');
             $element->setAttrib('id', 'editarea');
             $element->setAttrib('style', 'height:500px');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "password":
             $element = new Zend_Form_Element_Password($v['name']);
             break;
         case "textarea":
             $element = new Zend_Form_Element_Textarea($v['name']);
             $element->setAttrib('class', 'span9');
             $element->setAttrib('style', 'height:80px');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "hidden":
             $element = new Zend_Form_Element_Hidden($v['name']);
             $element->setValue($value);
             $element->setDecorators(array("ViewHelper"));
             break;
         case "textinput":
             $element = new Zend_Form_Element_Text($v['name']);
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "datepicker":
             $element = new Zend_Form_Element_Text($v['name']);
             $element->setAttrib('class', 'input-xlarge datepicker');
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "imageselect":
             $element = new Zend_Form_Element_Text($v['name']);
             $element->setAttrib('class', 'imageselector');
             $this->toTpl("hiddenEditor", 1);
             if ($value != '') {
                 $element->setValue($value);
             }
             break;
         case "selectbox":
             $element = new Zend_Form_Element_Select($v['name']);
             if ($v['use_pool'] && method_exists($this, $v['use_pool'])) {
                 if ($v['pool_type'] != '0') {
                     $this->pool_type = $v['pool_type'];
                 }
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($this->{$v}['use_pool']() as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
             } elseif (is_array($v['use_pool'])) {
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($v['use_pool'] as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
             } elseif ($v['use_pool']) {
                 //the pools might have been assigned by an addon
                 //include the file and run it.
                 require_once $this->dirs['structure']['addons'] . DIR_SEP . Zend_Registry::get('controller') . DIR_SEP . "func.php";
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($v['use_pool']($this) as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
             }
             break;
         case "multiselectbox":
             $element = new Zend_Form_Element_Multiselect($v['name']);
             $element->setAttrib('data-rel', 'chosen');
             if ($v['use_pool'] && method_exists($this, $v['use_pool'])) {
                 if ($v['pool_type'] != '0') {
                     $this->pool_type = $v['pool_type'];
                 }
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($this->{$v}['use_pool']() as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if (is_array($value)) {
                     foreach ($value as $a) {
                         $vals[] = $a['selected_value'];
                     }
                     $element->setValue($vals);
                 }
             } else {
                 //the pools might have been assigned by an addon
                 //include the file and run it.
                 require_once $this->dirs['structure']['addons'] . DIR_SEP . Zend_Registry::get('controller') . DIR_SEP . "func.php";
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 foreach ($v['use_pool']($this) as $ko => $vo) {
                     if ($v['noself'] && $vo['id'] == $v['noself']) {
                     } else {
                         $element->addMultiOption($vo['id'], $vo['title']);
                     }
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
             }
             break;
         case "treeselectbox":
             $element = new Zend_Form_Element_Select($v['name']);
             if ($v['use_pool'] && method_exists($this, $v['use_pool'])) {
                 if ($v['pool_type'] != '0') {
                     $this->pool_type = $v['pool_type'];
                 }
                 if ($v['novalue']) {
                     $element->addMultiOption(0, $this->t('No Selection'));
                 }
                 if ($value != '') {
                     $element->setValue($value);
                 }
                 //x10 times nested support. Needs fix
                 foreach ($this->{$v}['use_pool']() as $vo) {
                     $element->addMultiOption($vo['id'], $vo['title']);
                     foreach ($vo['kids'] as $a) {
                         $element->addMultiOption($a['id'], "|_" . $a['title']);
                         foreach ($a['kids'] as $b) {
                             $element->addMultiOption($b['id'], "|__" . $b['title']);
                             foreach ($b['kids'] as $c) {
                                 $element->addMultiOption($c['id'], "|___" . $c['title']);
                                 foreach ($c['kids'] as $d) {
                                     $element->addMultiOption($d['id'], "|____" . $d['title']);
                                     foreach ($d['kids'] as $e) {
                                         $element->addMultiOption($e['id'], "|_____" . $e['title']);
                                         foreach ($e['kids'] as $f) {
                                             $element->addMultiOption($f['id'], "|______" . $f['title']);
                                             foreach ($f['kids'] as $g) {
                                                 $element->addMultiOption($g['id'], "|______" . $g['title']);
                                                 foreach ($g['kids'] as $h) {
                                                     $element->addMultiOption($h['id'], "|_______" . $h['title']);
                                                     foreach ($h['kids'] as $i) {
                                                         $element->addMultiOption($i['id'], "|________" . $i['title']);
                                                         foreach ($i['kids'] as $j) {
                                                             $element->addMultiOption($j['id'], "|_________" . $j['title']);
                                                             foreach ($j['kids'] as $l) {
                                                                 $element->addMultiOption($l['id'], "|__________" . $l['title']);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
     }
     if ($v['required']) {
         $element->setRequired(true);
     }
     if ($v['title']) {
         $element->setLabel($v['title']);
     } else {
         $element->setLabel($this->t(ucfirst(str_replace("_", " ", $v['name']))));
     }
     if ($v['attributes']) {
         foreach ($v['attributes'] as $k => $r) {
             $element->setAttrib($k, $r);
         }
     }
     //$element->setDecorators(array("ViewHelper"));
     $element = $this->doQoolHook('post_getformelement_object', $element);
     return $element;
 }