public function init() { $registry = Zend_Registry::getInstance(); $this->addElementPrefixPath('Ml_Validate', 'Ml/Validate/', Zend_Form_Element::VALIDATE); $this->addElementPrefixPath('Ml_Filter', 'Ml/Filter/', Zend_Form_Element::FILTER); $signedUserInfo = $registry->get('signedUserInfo'); $uploadStatus = $registry->get("uploadStatus"); $this->setAttrib('enctype', 'multipart/form-data'); $this->setMethod('post'); $file = new Zend_Form_Element_File('file'); $file->setRequired(false); $file->setLabel('What do you want to share today?'); if ($uploadStatus['bandwidth']['remainingbytes'] > 0) { $maxFileSize = $uploadStatus['filesize']['maxbytes']; } else { $maxFileSize = 0; } $file->addValidator('Size', false, $maxFileSize); $file->setMaxFileSize($maxFileSize); $file->setMultiFile(4); $file->addValidator('Count', false, array('min' => 0, 'max' => 4)); $this->addElement($file, 'file'); $this->addElement(Ml_Model_MagicCookies::formElement()); $this->addElement('submit', 'submitupload', array('label' => 'Upload!', 'class' => 'btn primary')); $this->setAttrib('class', 'form-stacked'); }
/** * The default action - show the home page */ public function indexAction() { // Create form $form = new Zend_Form(); $form->setEnctype('multipart/form-data'); // File element... $fileEle = new Zend_Form_Element_File("projectImage", array('label' => 'Image File:')); $fileEle->setMultiFile(3); // Add elements + submit button $form->addElements(array($fileEle, new Zend_Form_Element_Submit('projectSubmitImageUpload', array('label' => 'Upload Image')))); // Show the form echo $form; // Check if we have a form post, and if it's valid if ($this->getRequest()->isPost() && $form->isValid($_POST)) { // you'll never get here! } }
public function init() { $this->form = new Image_Form_Edit(); $this->form->removeElement(Image::COL_ID); $this->form->removeElement(Image::COL_ORIGINAL_FILENAME); //create the upload element----------------------------- $element = new Zend_Form_Element_File('uploadElement'); $path = __FILE__; $path = dirname($path); $path = dirname($path); $path = dirname($path); $path = dirname($path); $path = dirname($path); $element->setLabel('Upload image(s):')->setDestination($path . '/public/images'); // ensure minimum 1, maximum 4 files $element->addValidator('Count', false, array('min' => 1, 'max' => 4)); // limit to 100K //$element->addValidator('Size', false, 102400); // only JPEG, PNG, and GIFs $element->addValidator('Extension', false, 'jpg,png,gif,jpeg'); // defines 4 identical file elements $element->setMultiFile(4); $element->setOrder(0); $this->form->addElement($element); //------------------------------------------------------ $fishSampleCode = new Zend_Form_Element_Text(Fish::COL_SAMPLE_CODE); $fishSampleCode->setLabel('Fish Sample Code:'); $fishSampleCode->setOrder(1); $this->form->addElement($fishSampleCode); //#####################new################################### $this->form->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'table', 'class' => 'login_form')), array('Description', array('placement' => 'prepend')), 'Form')); $this->form->setElementDecorators(array('ViewHelper', 'Errors', array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')), array('Label', array('tag' => 'td')), array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')))); $element->setDecorators(array('File', 'Errors', array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')), array('Label', array('tag' => 'td')), array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')))); //########################################################### $this->view->form = $this->form; }
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; }
/** * Inicializace formulare * */ public function init() { $this->setMethod(self::METHOD_POST); // ################## FIRST COLUMN ################### // Photo (id_foto) // File picker $profilePhotoPicker = new Zend_Form_Element_File('profilePhoto'); $profilePhotoPicker->setDestination(PUBLIC_PATH . '/temp'); $profilePhotoPicker->addValidator('Count', false, 1); $profilePhotoPicker->addValidator('Size', false, 2097152); $profilePhotoPicker->removeDecorator('Label'); $this->addElement($profilePhotoPicker, 'profilePhoto'); $avatar = new Zend_Form_Element_Image('avatar'); $avatar->setAttrib('class', array("profile-user-img", "img-responsive", "img-circle")); $this->addElement($avatar, 'avatar'); // First name (jmeno) $firstName = $this->createElement('text', 'jmeno'); $firstName->addFilter('StringTrim'); $firstName->setRequired(true); $firstName->setAttrib('class', 'form-control'); $firstName->setAttrib('placeholder', 'First name'); $firstName->removeDecorator('Label'); $this->addElement($firstName); // Last name (prijmeni) $lastName = $this->createElement('text', 'prijmeni'); $lastName->addFilter('StringTrim'); $lastName->setRequired(true); $lastName->setAttrib('class', 'form-control'); $lastName->setAttrib('placeholder', 'Surname'); $lastName->removeDecorator('Label'); $this->addElement($lastName); // Date of birth (datum_narozeni) // Date picker $birthdate = $this->createElement('text', 'datum_narozeni'); $birthdate->setRequired(true); $birthdate->setAttrib('class', array('form-control', 'date-picker')); $birthdate->removeDecorator('Label'); $birthdate->setAttrib('placeholder', 'Birthdate'); $this->addElement($birthdate); // ################## SECOND COLUMN ################## // Status (id_status) // Select box $status = new Zend_Form_Element_Select('id_status'); $status->removeDecorator('Label'); $status->setAttrib('class', 'form-control'); $this->addElement($status, 'id_status'); // Position (id_pozice) // Select box $position = new Zend_Form_Element_Select('id_pozice'); $position->removeDecorator('Label'); $position->setAttrib('class', 'form-control'); $this->addElement($position, 'id_pozice'); // Technology (kandidat_technologie) // Multi select $technology = new Zend_Form_Element_Multiselect('kandidat_technologie'); $technology->removeDecorator('Label'); $technology->setAttrib('class', 'form-control'); $this->addElement($technology, 'kandidat_technologie'); // Seniority (id_seniorita) // Select box $seniority = new Zend_Form_Element_Select('id_seniorita'); $seniority->removeDecorator('Label'); $seniority->setAttrib('class', 'form-control'); $this->addElement($seniority, 'id_seniorita'); // Comment (komentar) $comment = $this->createElement('textarea', 'komentar'); $comment->addFilter('StringTrim'); $comment->setAttrib('class', 'form-control'); $comment->setAttrib('rows', '3'); $comment->setAttrib('placeholder', 'Enter your comment…'); $comment->removeDecorator('Label'); $this->addElement($comment); // ################### ATTACHEMENTS ################### // Attchements (kandidat_priloha) // File picker $attachments = new Zend_Form_Element_File('attachments'); $attachments->setDestination(PUBLIC_PATH . '/temp'); $attachments->addValidator('Count', false, array('min' => 0, 'max' => 4)); $attachments->addValidator('Size', false, 2097152); $attachments->setMultiFile(4); $attachments->removeDecorator('Label'); $this->addElement($attachments, 'attachments'); $attachmentsCheckGroup = new Zend_Form_Element_MultiCheckbox('attachmentsCheckGroup'); $comment->removeDecorator('Label'); $this->addElement($attachmentsCheckGroup, 'attachmentsCheckGroup'); // ###################### BUTTON ###################### $close = new Zend_Form_Element_Submit('closeButton'); $close->setLabel('Back'); $close->setAttrib('class', 'btn btn-default'); $close->setDecorators(array('ViewHelper')); $this->addElement($close, 'closeButton'); $save = new Zend_Form_Element_Submit('saveButton'); $save->setLabel('Save'); $save->setAttrib('class', 'btn btn-success'); $save->setDecorators(array('ViewHelper')); $this->addElement($save, 'saveButton'); $delete = new Zend_Form_Element_Submit('deleteButton'); $delete->setLabel('Delete'); $delete->setAttrib('class', 'btn btn-danger'); $delete->setAttrib('onclick', 'if (confirm("Are you sure?")) { document.form.submit(); } return false;'); $delete->setDecorators(array('ViewHelper')); $this->addElement($delete, 'deleteButton'); }
/** * 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; }
public function testMultiFileWithOneFile() { $form = new Zend_Form(); $element = new Zend_Form_Element_File('file'); $element->setMultiFile(1); $subform0 = new Zend_Form_SubForm(); $subform0->addElement($element); $subform1 = new Zend_Form_SubForm(); $subform1->addSubform($subform0, 'subform0'); $subform2 = new Zend_Form_SubForm(); $subform2->addSubform($subform1, 'subform1'); $subform3 = new Zend_Form_SubForm(); $subform3->addSubform($subform2, 'subform2'); $form->addSubform($subform3, 'subform3'); $form->setView(new Zend_View()); $output = (string) $form; $this->assertNotContains('name="file[]"', $output); }
public function advfileAction() { $this->view->Title = "Manage advertising picture gallery"; $this->view->headTitle($this->view->Title); $dir = ROOT_DIR . DATA_DIR . '/adv'; if ($this->getRequest()->isPost()) { $images = new Zend_Form_Element_File('images'); $images->setDestination($dir); //$element->addValidator ( 'Size', false, 512000 ); $images->addValidator('Extension', false, 'jpg,png,gif,swf'); $images->setMultiFile(count($_POST['images'])); $images->receive(); } if ($this->getRequest()->getParam('delete')) { @unlink($dir . '/' . $this->getRequest()->getParam('delete')); } $this->view->Adv = self::getFileDir($dir); }
public function testMultiFileInSubSubSubform() { $form = new Zend_Form(); $element = new Zend_Form_Element_File('file'); $element->setMultiFile(2); $subform0 = new Zend_Form_SubForm(); $subform0->addElement($element); $subform1 = new Zend_Form_SubForm(); $subform1->addSubform($subform0, 'subform0'); $subform2 = new Zend_Form_SubForm(); $subform2->addSubform($subform1, 'subform1'); $subform3 = new Zend_Form_SubForm(); $subform3->addSubform($subform2, 'subform2'); $form->addSubform($subform3, 'subform3'); $form->setView(new Zend_View()); $output = (string) $form; $this->assertContains('name="file[]"', $output); $this->assertEquals(2, substr_count($output, 'file[]')); }