public function addElements() { //-- File -- $file = new Element\File('file'); $file->setAttribute('placeholder', 'profile_name'); $file->setAttribute('required', 'true'); $file->setAttribute('class', 'form-control'); $file->setAttribute('id', 'file'); $file->setLabel('Profile name'); $file->setLabelAttributes(array('class' => 'control-label', 'for' => 'file')); //-- Submit -- $submit = new Element\Submit('submit'); $submit->setAttribute('class', 'btn btn-success'); $submit->setValue('Send'); //-- Binding elements -- $this->add($file); $this->add($submit); }
public function addElements($multi) { $file = new Element\File('upload'); $file->setLabel('Bild hinzufügen:')->setAttribute('id', 'file'); if ($multi !== null) { $file->setAttribute('multiple', true); } $this->add($file); $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Hochladen'))); }
public function __construct(array $profileOptions, array $config) { parent::__construct(); $this->setAttribute('method', 'post'); foreach ($profileOptions as $profileOption) { switch ($profileOption['inputType']) { case ProfileOptionForm::INPUT_TYPE_TEXTAREA: $element = new Textarea($profileOption['name']); break; case ProfileOptionForm::INPUT_TYPE_TEXT: $element = new Text($profileOption['name']); break; case ProfileOptionForm::INPUT_TYPE_DATE: $element = new Text($profileOption['name']); break; case ProfileOptionForm::INPUT_TYPE_TIME: $element = new Text($profileOption['name']); break; case ProfileOptionForm::INPUT_TYPE_DATETIME: $element = new Text($profileOption['name']); break; case ProfileOptionForm::INPUT_TYPE_PICTURE_UPLOAD: $element = new File($profileOption['name']); $element->prepareElement($this); if (array_key_exists($profileOption['name'], $config['upload_target'])) { $uploadTarget = $config['upload_target'][$profileOption['name']]; } else { $uploadTarget = $config['upload_target']['default']; } $this->inputFilterSpec[] = ['type' => FileInput::class, 'name' => $profileOption['name'], 'required' => false, 'filters' => [['name' => 'filerenameupload', 'options' => ['target' => $uploadTarget, 'randomize' => true, 'use_upload_extension' => true]]], 'validators' => [['name' => 'fileisimage']]]; break; default: break 2; } $element->setLabel($profileOption['name']); $element->setAttribute('class', 'form-control'); $this->add($element); } $submit = new Submit('save'); $submit->setValue('save'); $submit->setAttribute('class', 'btn btn-primary'); $this->add($submit); }
public function init() { $fileupload = new Element\File('files'); $fileupload->setLabel("files"); $fileupload->setAttribute('multiple', 'multiple'); $this->add($fileupload); $button = new Element\Button('start'); $button->setAttribute("type", 'submit'); $button->setValue("Start upload")->setLabel("Start upload"); $this->add($button); $button = new Element\Button('cancel'); $button->setAttribute("type", 'reset'); $button->setValue("Cancel upload")->setLabel("Cancel upload"); $this->add($button); $button = new Element\Button('delete'); $button->setAttribute("type", 'button'); $button->setValue("Delete")->setLabel("Delete"); $this->add($button); $checkbox = new Element\Checkbox('toggle'); $checkbox->setValue("Toggle")->setLabel("Toggle"); $checkbox->setAttribute("required", ""); $this->add($checkbox); }
/** * Load upload editor * * @return mixed */ public function load() { $parameters = $this->getConfig(); $property = $this->getProperty(); $upload = new Element\File($this->getName()); $value = $this->getValue(); $upload->setLabel($property->getName()); $upload->setAttribute('class', 'form-control')->setAttribute('id', $this->getName()); if (!empty($parameters['is_multiple'])) { $upload->setAttribute('multiple', 'multiple'); $upload->setName($upload->getName()); } $hiddenUpload = new Element\Hidden($this->getName() . '-hidden'); if (!empty($value)) { $hiddenUpload->setValue($value); } return array($upload, $hiddenUpload, $this->addPath(__DIR__)->render('upload-editor.phtml', array('files' => $value, 'id' => $this->getName(), 'isMultiple' => $parameters['is_multiple']))); }
/** * Load Image cropper editor * * @return mixed */ public function load() { $parameters = $this->getConfig(); $property = $this->getProperty(); $upload = new Element\File($this->getName()); $upload->setAttribute('class', 'form-control'); $upload->setAttribute('required', $property->isRequired()); $upload->setLabel($property->getName()); $hiddenUpload = new Element\Hidden($this->getName() . '-hidden'); $value = $this->getValue(); if (!empty($value)) { $hiddenUpload->setValue($value); $value = unserialize($value); if (is_array($value)) { foreach ($value as $name => $file) { if ($name == 'original') { continue; } $found = false; foreach ($parameters['size'] as $size) { if ($size['name'] == $name) { $found = true; $file['options'] = $size; break; } } if (empty($found)) { unset($value[$name]); } } } } $this->getHelper('HeadLink')->appendStylesheet('/backend/assets/datatypes/imagecropper/jquery.jcrop.min.css'); $this->getHelper('HeadLink')->appendStylesheet('/backend/assets/datatypes/imagecropper/image-cropper.css'); $this->getHelper('HeadScript')->appendFile('/backend/assets/datatypes/imagecropper/jquery.jcrop.min.js'); return array($upload, $hiddenUpload, $this->addPath(__DIR__)->render('upload-editor.phtml', array('files' => $value, 'id' => $this->getName(), 'options' => $parameters, 'name' => $this->getName()))); }
/** * @return void */ public function testNameShouldHaveArrayNotationWhenMultipleIsSpecified() { $element = new Element\File('foo'); $element->setAttribute('multiple', true); $markup = $this->helper->render($element); $this->assertRegexp('#<input[^>]*?(name="foo\\[\\]")#', $markup); }
/** * * @param string $name * @param string $type * @param array $values */ protected function generateFormElement($name, $type, $values = array(), $priority = 100) { $options = $this->getOptions(); $option_elements = $options['form']['elements']; switch (strtoupper($type)) { case 'TEXT': case 'CHAR': case 'VARCHAR': $elm = new Element($name); $elm->setLabel(strtoupper($name)); $elm->setAttribute('id', $name . '_ID'); $elm->setAttributes(array('type' => 'text')); break; case 'ENUM': $elm = new Element\Select($name); $elm->setLabel(strtoupper($name)); $elm->setAttribute('id', $name . '_ID'); if ($values instanceof \Traversable) { $elm->setValueOptions($values); } break; case 'INT': case 'INTEGER': case 'NUMERIC(10, 0)': case 'DECIMAL': case 'NUMERIC': case 'DOUBLE': $elm = new Element($name); $elm->setLabel(strtoupper($name)); $elm->setAttribute('id', $name . '_ID'); $elm->setAttributes(array('type' => 'number')); break; case 'DATE': if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') { $elm = new \Zf2datatable\Form\Element\DateCalendar($name); $elm->setAttribute('id', $name . '_ID'); $elm->setAttribute('class', 'form-control'); $elm->setLabel($name); $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['date_js_properties']); \Zf2datatable\Form\Element\DateCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['date_format_in']); \Zf2datatable\Form\Element\DateCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['date_format_out']); \Zf2datatable\Form\Element\DateCalendar::setDateFormatMaskIn($option_elements['DateTimePicker']['options']['date_format_mask_in']); \Zf2datatable\Form\Element\DateCalendar::setDateFormatMaskOut($option_elements['DateTimePicker']['options']['date_format_mask_out']); } else { $elm = new Element\Date($name); $elm->setLabel(strtoupper($name)); $elm->setAttributes(array('type' => 'date')); $elm->setFormat('Y-m-d'); } break; case 'DATETIME': if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') { $elm = new \Zf2datatable\Form\Element\DateTimeCalendar($name); $elm->setAttribute('id', $name . '_ID'); $elm->setAttribute('class', 'form-control'); $elm->setLabel($name); $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['datetime_js_properties']); \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['datetime_format_in']); \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['datetime_format_out']); \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatMaskIn($option_elements['DateTimePicker']['options']['datetime_format_mask_in']); \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatMaskOut($option_elements['DateTimePicker']['options']['datetime_format_mask_out']); } else { $elm = new Element\DateTimeSelect($name); $elm->setLabel(strtoupper($name)); } break; case 'FILE': $elm = new Element\File(); $elm->setLabel(strtoupper($name)); $elm->setAttribute('id', $name . '_ID'); break; default: $elm = new Element($name); $elm->setLabel(strtoupper($name)); $elm->setAttribute('id', $name . '_ID'); $elm->setAttributes(array('type' => 'text')); } $elm->setOption('priority', $priority); return $elm; }