/** * Load checkbox list editor * * @return Element\MultiCheckbox */ public function load() { $parameters = $this->getConfig(); $element = new Element\MultiCheckbox($this->getName()); if (!empty($parameters)) { $element->setValueOptions($parameters); } $element->setLabel($this->getProperty()->getName())->setAttribute('id', $this->getName())->setAttribute('required', $this->getProperty()->isRequired())->setAttribute('class', 'input-checkbox')->setValue($this->getValue()); return $element; }
protected function addMultiCheckbox($name, $label, array $data) { $multiCheckbox = new Element\MultiCheckbox($name); $multiCheckbox->setLabel($label); $multiCheckbox->setLabelAttributes(array('class' => "col-sm-{$this->labelWidth}")); $multiCheckbox->setValueOptions($data); $multiCheckbox->setOption('column-size', "sm-{$this->controlWidth}"); $multiCheckbox->setOption('inline', true); $this->add($multiCheckbox); return $this; }
public function testCanHandleMultiCheckboxesCorrectly() { $options = array('This is the first label' => 'value1', 'This is the second label' => 'value2', 'This is the third label' => 'value3'); $element = new Element\MultiCheckbox('foo'); $element->setAttribute('type', 'multi_checkbox'); $element->setAttribute('options', $options); $element->setLabel('This is a multi-checkbox'); $markup = $this->helper->render($element); $this->assertContains("<fieldset>", $markup); $this->assertContains("<legend>", $markup); $this->assertContains("<label>", $markup); }
function __construct(array $associations = []) { parent::__construct('taxonomyTerm'); $this->setAttribute('method', 'post'); $filter = new InputFilter(); $this->setInputFilter($filter); $this->add((new Text('destination'))->setAttribute('id', 'destination')->setAttribute('placeholder', 'ID (12345)')->setLabel('Move to:')); $multiCheckbox = new MultiCheckbox('associations'); $multiCheckbox->setLabel('Elements')->setAttribute('id', 'associations'); $multiCheckbox->setValueOptions($associations); $this->add($multiCheckbox); $this->add((new Submit('submit'))->setValue('Save')->setAttribute('class', 'btn btn-success pull-right')); $filter->add(['name' => 'destination', 'required' => true, 'allow_empty' => false, 'filters' => [['name' => 'Int']], 'validators' => [['name' => 'Digits']]]); }
public function __construct() { parent::__construct('AddRecipeForm'); $noOfPeopleElement = new Text('NoOfPeople'); $noOfPeopleElement->setLabel('Anzahl Personen'); $this->add($noOfPeopleElement); // Add Text for kcal. //TODO: Rescrict input to integers $kcalElement = new Text('Kcal'); $kcalElement->setLabel('Anzahl Kalorien'); $this->add($kcalElement); // Add Checkbox for publicFlag $publicFlagElement = new Checkbox('PublicFlag'); $publicFlagElement->setLabel('Möchten Sie das Rezept öffentlich speichern?'); $this->add($publicFlagElement); $preparationTimeElement = new Text('PreparationTime'); $preparationTimeElement->setLabel('Vorbereitungszeit'); $this->add($preparationTimeElement); $cookingTimeElement = new Text('CookingTime'); $cookingTimeElement->setLabel('Koch- / Backzeit'); $this->add($cookingTimeElement); $restingTimeElement = new Text('RestingTime'); $restingTimeElement->setLabel('Ruhezeit'); $this->add($restingTimeElement); $types = $this->selectAllFrom('Types', 'Name'); $typeElement = new MultiCheckbox('TypeId'); $typeElement->setLabel('Rezept Typ'); //$possibleValues = array('Sommermenu','Herbstmenu','Wintermenu','Frühlingsmenu'); $typeElement->setValueOptions($types); $this->add($typeElement); $levels = $this->selectAllFrom('Levels', 'Shortname'); $levelElement = new Select('Level'); $levelElement->setLabel('Schwierigkeit'); $levelElement->setValueOptions($levels); /*array('einfach','schwierig'));*/ $levelElement->setValue($levels[0]); $this->add($levelElement); // Add steps $this->addSteps($this->getMaxNumberOfSteps()); // Add select for chosing how many steps should be displayed $stepNumbers = range(1, $this->maxNoOfSteps); $addStepSelect = new Select('StepNumber'); $addStepSelect->setLabel('Anzahl Schritte wählen'); $addStepSelect->setValueOptions($stepNumbers); $addStepSelect->setAttribute('id', 'NoOfStepSelect'); $addStepSelect->setAttribute('onchange', 'show(++this.value)'); $this->add($addStepSelect); }
public function __construct() { $dbAdapter = Zend\Db\TableGateway\Feature\GlobalAdapterFeature::getStaticAdapter(); $this->setDbAdapter($dbAdapter); parent::__construct('recipefieldset'); $this->add(array('name' => 'noOfPeople', 'type' => 'Text', 'options' => array('label' => 'Anzahl Personen'))); // Add Text for kcal. //TODO: Rescrict input to integers $kcalElement = new Text('kcal'); $kcalElement->setLabel('Anzahl Kalorien'); $this->add($kcalElement); // Add Checkbox for publicFlag $publicFlagElement = new Checkbox('publicFlag'); $publicFlagElement->setLabel('Möchten Sie das Rezept öffentlich speichern?'); $this->add($publicFlagElement); $typeElement = new MultiCheckbox('typeId'); $typeElement->setLabel('Rezept Typ'); $possibleValues = array('Sommermenu', 'Herbstmenu', 'Wintermenu', 'Frühlingsmenu'); $typeElement->setValueOptions($possibleValues); $this->add($typeElement); $selectString = 'SELECT * FROM Levels'; //$select->getSqlString(); $result = $dbAdapter->query($selectString, Adapter::QUERY_MODE_EXECUTE); $levels = array(); foreach ($result as $row) { $levels[] = $row['Shortname']; } $levelElement = new Select('level'); $levelElement->setLabel('Schwierigkeit'); $levelElement->setValueOptions($levels); /*array('einfach','schwierig'));*/ $this->add($levelElement); // Add steps $this->addSteps(4); $stepNumbers = range(1, $this->maxNoOfSteps); $addStepSelect = new Select('stepNumber'); $addStepSelect->setLabel('Anzahl Schritte wählen'); $addStepSelect->setValueOptions($stepNumbers); $addStepSelect->setAttribute('id', 'noOfStepSelect'); $addStepSelect->setAttribute('onchange', 'show()'); $this->add($addStepSelect); }
public function __construct(array $roles) { parent::__construct(); $this->setAttribute('method', 'post'); $this->setAttribute('class', 'panel-body'); $name = new Text('name'); $name->setLabel('name'); $name->setAttribute('class', 'form-control'); $this->add($name); $parent = new MultiCheckbox('parent'); $parent->setLabel('parent'); $parent->setUseHiddenElement(true); $parent->setValueOptions($roles); $this->add($parent); $this->getInputFilter()->get($parent->getName())->setAllowEmpty(true); $submit = new Submit('save'); $submit->setValue('save'); $submit->setAttribute('class', 'btn btn-primary'); $this->add($submit); }
/** * @param TableModel $table */ public function __construct(TableModel $table) { parent::__construct('Display'); $this->tableModel = $table; $tableHeaders = $this->tableModel->getTableHeaders(); // Group checkboxes by property $columnGroups = array(); foreach ($tableHeaders as $tableHeader) { /** @var TableHeaderCellModel $tableHeader */ $columnNameSegments = explode('.', $tableHeader->getName()); if (!array_key_exists($columnNameSegments[0], $columnGroups)) { $columnGroups[$columnNameSegments[0]] = array(); } } // Create all values for each property foreach ($tableHeaders as $tableHeader) { $columnNameSegments = explode('.', $tableHeader->getName()); $label = $tableHeader->getName(); if (count($columnNameSegments) > 1) { $segments = $columnNameSegments; unset($segments[0]); $label = implode('.', $segments); } $valueOption = array('value' => $tableHeader->getName(), 'label' => $label, 'selected' => $tableHeader->isVisible()); $columnGroups[$columnNameSegments[0]][] = $valueOption; } // Create the actual form element per property foreach ($columnGroups as $property => $checkboxValues) { $multiCheckbox = new MultiCheckbox($this->checkboxName); $multiCheckbox->setOptions(array('inline' => false, 'value_options' => $checkboxValues)); $isParentField = strpos($checkboxValues[0]['value'], ".") !== false; if (count($checkboxValues) >= 2 || count($checkboxValues) == 1 && $isParentField) { $multiCheckbox->setLabel($property); } // Dirty hack, because this->add() does not detect element or fieldset naming conflicts $this->iterator->insert($property, $multiCheckbox, 0); } $this->add(array('name' => 'submit', 'type' => 'submit', 'label' => '<span class="glyphicon glyphicon glyphicon-refresh"></span>', 'attributes' => array('value' => 'Apply', 'class' => 'btn knopSearch'))); }
public function formAction() { // Build a name element. $name = new Element('name'); $name->setLabel('Your name'); $name->setAttributes(array('type' => 'text')); // Build a submit button element. $send = new Element('send'); $send->setLabel('Send'); $send->setAttributes(array('type' => 'submit', 'value' => 'Send')); // Build a checkbox element. $check = new Checkbox('check'); $check->setLabel('Checkbox example'); // Build a multi-checkbox element. $multicheck = new MultiCheckbox('multicheck'); $multicheck->setLabel('Multi checkbox example'); $multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two'))); // Assemble the form. $form = new Form('contact'); $form->add($name); $form->add($check); $form->add($multicheck); $form->add($send); // Get the request if any. $request = $this->getRequest(); $data = $request->getPost(); $form->setData($data); // Validate the form if ($form->isValid()) { $validatedData = $form->getData(); $success = 'Form submit was successful'; } else { $success = 'Form submit failed'; $messages = $form->getMessages(); } // Set the method attribute for the form $form->setAttribute('method', 'post'); return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data)); }
public function testShowErrorInMultiCheckbox() { $element = new Element\MultiCheckbox('hobby'); $element->setLabel("Hobby"); $element->setValueOptions(array('0' => 'working', '1' => 'coding')); $element->setMessages(array('Error message')); $markup = $this->helper->__invoke($element); $this->assertContains('<ul><li>Error message</li></ul>', $markup); }
/** * Builds fieldset with additional properties for the "monthly" repeat picker value. * It returns the built fieldset (used as a child of the "repeat" fieldset). * * @return Fieldset */ public function getRepeatMonthlyFieldset() { $repeatMonthlyFieldset = new Fieldset(self::MONTHLY); // Note that this field is rendered on the frontend without the view helper, // for more flexibility. $dayOfMonth = new Element\MultiCheckbox('dayOfMonth'); $dayOfMonth->setLabel('Pick days'); $dayOfMonth->setValueOptions(array_combine(range(1, 31), range(1, 31))); $repeatMonthlyFieldset->add($dayOfMonth); return $repeatMonthlyFieldset; }
public function render($formPV, $id) { $form = new Form(); $form->setAttribute('id', $id); $inputFilter = new \Zend\InputFilter\InputFilter(); $factory = new InputFactory(); foreach ($formPV as $element) { if (isset($element->line_text)) { $attributes = $element->line_text[0]; $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $placeholder = isset($attributes->data->placeholder) ? $attributes->data->placeholder : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; //$required = ($attributes->data->required == 'true') ? true : false ; $required = false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $lengthMin = isset($attributes->data->length) ? $attributes->data->length->min : ''; $lengthMax = isset($attributes->data->length) ? $attributes->data->length->max : ''; $element = new Element\Text($name); $element->setName($label); $element->setLabel($label); $element->setAttributes(array('placeholder' => $placeholder, 'required' => $required, 'class' => $class, 'id' => $id)); $form->add($element); $options = array(); $options['encoding'] = 'UTF-8'; if ($lengthMin && $lengthMin > 0) { $options['min'] = $lengthMin; } if ($lengthMax && $lengthMax > $lengthMin) { $options['max'] = $lengthMax; $element->setAttribute('maxlength', $lengthMax); $options['messages'] = array(\Zend\Validator\StringLength::TOO_LONG => sprintf($this->getServiceManager()->get('translator')->translate('This field contains more than %s characters', 'playgroundgame'), $lengthMax)); } $inputFilter->add($factory->createInput(array('name' => $name, 'required' => $required, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => $options))))); } if (isset($element->line_email)) { $attributes = $element->line_email[0]; $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $placeholder = isset($attributes->data->placeholder) ? $attributes->data->placeholder : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; //$required = ($attributes->data->required == 'true') ? true : false ; $required = false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $lengthMin = isset($attributes->data->length) ? $attributes->data->length->min : ''; $lengthMax = isset($attributes->data->length) ? $attributes->data->length->max : ''; $element = new Element\Email($name); $element->setLabel($label); $element->setName($label); $element->setAttributes(array('placeholder' => $placeholder, 'required' => $required, 'class' => $class, 'id' => $id)); $form->add($element); $options = array(); $options['encoding'] = 'UTF-8'; if ($lengthMin && $lengthMin > 0) { $options['min'] = $lengthMin; } if ($lengthMax && $lengthMax > $lengthMin) { $options['max'] = $lengthMax; $element->setAttribute('maxlength', $lengthMax); $options['messages'] = array(\Zend\Validator\StringLength::TOO_LONG => sprintf($this->getServiceManager()->get('translator')->translate('This field contains more than %s characters', 'playgroundgame'), $lengthMax)); } $inputFilter->add($factory->createInput(array('name' => $name, 'required' => $required, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => $options))))); } if (isset($element->line_checkbox)) { $attributes = $element->line_checkbox[0]; $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; // $required = ($attributes->data->required == 'yes') ? true : false; $required = false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $lengthMin = isset($attributes->data->length) ? $attributes->data->length->min : ''; $lengthMax = isset($attributes->data->length) ? $attributes->data->length->max : ''; $innerData = isset($attributes->data->innerData) ? $attributes->data->innerData : array(); $element = new Element\MultiCheckbox($name); $element->setLabel($label); $element->setName($label); $element->setAttributes(array('name' => $name, 'required' => $required, 'allowEmpty' => !$required, 'class' => $class, 'id' => $id)); $values = array(); foreach ($innerData as $value) { $values[] = $value->label; } $element->setValueOptions($values); $form->add($element); $options = array(); $options['encoding'] = 'UTF-8'; $inputFilter->add($factory->createInput(array('name' => $name, 'required' => $required, 'allowEmpty' => !$required))); } if (isset($element->line_paragraph)) { $attributes = $element->line_paragraph[0]; $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $placeholder = isset($attributes->data->placeholder) ? $attributes->data->placeholder : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; $required = $attributes->data->required == 'true' ? true : false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $lengthMin = isset($attributes->data->length) ? $attributes->data->length->min : ''; $lengthMax = isset($attributes->data->length) ? $attributes->data->length->max : ''; $element = new Element\Textarea($name); $element->setName($label); $element->setLabel($label); $element->setAttributes(array('placeholder' => $placeholder, 'required' => $required, 'class' => $class, 'id' => $id)); $form->add($element); $options = array(); $options['encoding'] = 'UTF-8'; if ($lengthMin && $lengthMin > 0) { $options['min'] = $lengthMin; } if ($lengthMax && $lengthMax > $lengthMin) { $options['max'] = $lengthMax; $element->setAttribute('maxlength', $lengthMax); } $inputFilter->add($factory->createInput(array('name' => $name, 'required' => $required, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => $options))))); } if (isset($element->line_upload)) { $attributes = $element->line_upload[0]; //print_r($attributes); $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; $required = $attributes->data->required == 'true' ? true : false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $filesizeMin = isset($attributes->data->filesize) ? $attributes->data->filesize->min : ''; $filesizeMax = isset($attributes->data->filesize) ? $attributes->data->filesize->max : ''; $element = new Element\File($name); $element->setLabel($label); $element->setName($label); $element->setAttributes(array('required' => $required, 'class' => $class, 'id' => $id)); $form->add($element); $inputFilter->add($factory->createInput(array('name' => $name, 'required' => $required, 'validators' => array(array('name' => '\\Zend\\Validator\\File\\Size', 'options' => array('max' => 10 * 1024 * 1024)), array('name' => '\\Zend\\Validator\\File\\Extension', 'options' => array('png,PNG,jpg,JPG,jpeg,JPEG,gif,GIF', 'messages' => array(\Zend\Validator\File\Extension::FALSE_EXTENSION => 'Veuillez télécharger une image'))))))); } if (isset($element->line_radio)) { $attributes = $element->line_radio[0]; $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; // $required = ($attributes->data->required == 'yes') ? true : false; $required = false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $lengthMin = isset($attributes->data->length) ? $attributes->data->length->min : ''; $lengthMax = isset($attributes->data->length) ? $attributes->data->length->max : ''; $innerData = isset($attributes->data->innerData) ? $attributes->data->innerData : array(); $element = new Element\Radio($name); $element->setLabel($label); $element->setName($label); $element->setAttributes(array('name' => $name, 'required' => $required, 'allowEmpty' => !$required, 'class' => $class, 'id' => $id)); $values = array(); foreach ($innerData as $value) { $values[] = $value->label; } $element->setValueOptions($values); $form->add($element); } if (isset($element->line_dropdown)) { $attributes = $element->line_dropdown[0]; $name = isset($attributes->name) ? $attributes->name : ''; $type = isset($attributes->type) ? $attributes->type : ''; $position = isset($attributes->order) ? $attributes->order : ''; $label = isset($attributes->data->label) ? $attributes->data->label : ''; // $required = ($attributes->data->required == 'yes') ? true : false; $required = false; $class = isset($attributes->data->class) ? $attributes->data->class : ''; $id = isset($attributes->data->id) ? $attributes->data->id : ''; $lengthMin = isset($attributes->data->length) ? $attributes->data->length->min : ''; $lengthMax = isset($attributes->data->length) ? $attributes->data->length->max : ''; $dropdownValues = isset($attributes->data->dropdownValues) ? $attributes->data->dropdownValues : array(); $element = new Element\Select($name); $element->setLabel($label); $element->setName($label); $element->setAttributes(array('name' => $name, 'required' => $required, 'allowEmpty' => !$required, 'class' => $class, 'id' => $id)); $values = array(); foreach ($dropdownValues as $value) { $values[] = $value->dropdown_label; } $element->setValueOptions($values); $form->add($element); } } $form->setInputFilter($inputFilter); return $form; }
/** * Prepara os campos do formulário * @param string $fieldName * @param array $fieldParams * @param array $options * @return object * @throws Exception */ private function prepareFields($fieldName, array $fieldParams, array $options = array()) { $element = null; $extraLabel = " "; $this->aOptions = array(); $this->aAttributes = array(); /* Define o tooltip do campo */ $tooltip = (isset($fieldParams['tooltip']) and $fieldParams['tooltip'] == 'true') ? "<a class=\"tooltip-marc\" href=\"#\" data-toggle=\"tooltip\" title=\"{$this->getTranslator($fieldName . '_tooltip')}\">[?]</a>" : null; $this->aOptions['tooltip'] = $tooltip; /* Define como será mostrado o nome do campo (se é obrigatório ou não) */ if (strtolower($fieldParams['type']) != 'hidden') { if (isset($fieldParams['validation']) and stristr(strtolower($fieldParams['validation']), "required")) { $extraLabel = " * "; } } switch (strtolower($fieldParams['type'])) { /* Caso hidden */ case 'primary': case 'hidden': $element = new ZendFormElement\Hidden($fieldName); break; /* Caso Csrf */ /* Caso Csrf */ case 'csrf': case 'sec': $element = new ZendFormElement\Csrf($fieldName); $element->setCsrfValidatorOptions(array('timeout' => '600')); break; /* Caso text */ /* Caso text */ case 'text': $element = new ZendFormElement\Text($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'form-input'; break; /* Caso textarea */ /* Caso textarea */ case 'textarea': $element = new ZendFormElement\Textarea($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); /* Define os padrões de colunas e linhas do campo */ $this->aAttributes['rows'] = (isset($fieldParams['rows']) and !empty($fieldParams['rows'])) ? $fieldParams['rows'] : 5; $this->aAttributes['cols'] = (isset($fieldParams['cols']) and !empty($fieldParams['cols'])) ? $fieldParams['cols'] : 10; $this->aAttributes['class'] = 'form-input'; $this->aAttributes['data-editor'] = 'false'; break; /* Caso editor */ /* Caso editor */ case 'editor': $element = new ZendFormElement\Textarea($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); /* Define os padrões de colunas e linhas do campo */ $this->aAttributes['rows'] = (isset($fieldParams['rows']) and !empty($fieldParams['rows'])) ? $fieldParams['rows'] : 5; $this->aAttributes['cols'] = (isset($fieldParams['cols']) and !empty($fieldParams['cols'])) ? $fieldParams['cols'] : 10; /* Verifica se utilizará o editor */ $this->aAttributes['class'] = 'editorw'; $this->aAttributes['data-editor'] = 'true'; /* Verifica a pasta de upload */ if (isset($this->formDefaultConfig['destination']) and !empty($this->formDefaultConfig['destination'])) { /* Caso não exista a pasta cria o mesmo */ if (!is_dir(UPLOAD_PATH . $this->formDefaultConfig['destination'])) { mkdir(UPLOAD_PATH . $this->formDefaultConfig['destination'], 0777, true); chmod(UPLOAD_PATH . $this->formDefaultConfig['destination'], 0777); } $_SESSION['KCFINDER'] = array(); $_SESSION['KCFINDER']['disabled'] = false; $_SESSION['KCFINDER']['uploadURL'] = URL_UPLOAD . $this->formDefaultConfig['destination']; $_SESSION['KCFINDER']['uploadDir'] = UPLOAD_PATH . $this->formDefaultConfig['destination']; } else { throw new \Exception('Defina a pasta de destino de upload das imagens do editor!', 500); } break; /* Caso password */ /* Caso password */ case 'password': $element = new ZendFormElement\Password($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['renderPassword'] = true; $this->aAttributes['class'] = 'form-input'; break; /* Caso radio */ /* Caso radio */ case 'radio': $element = new ZendFormElement\Radio($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'radio'; break; /* Caso checkbox */ /* Caso checkbox */ case 'checkbox': $element = new ZendFormElement\Checkbox($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $element->setUncheckedValue(null); $this->aAttributes['class'] = 'checkbox'; break; /* Caso multicheckbox */ /* Caso multicheckbox */ case 'multicheckbox': $element = new ZendFormElement\MultiCheckbox($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $element->setUncheckedValue(null); break; /* Caso select */ /* Caso select */ case 'select': $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true)); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->selectOptions = array(); if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') { $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder'); } else { $this->selectOptions[''] = "---------"; } $this->aAttributes['class'] = 'form-input-select'; break; /* Caso selectgroup */ /* Caso selectgroup */ case 'selectgroup': $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true)); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->selectOptions = array(); if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') { $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder'); } else { $this->selectOptions[''] = "---------"; } $this->aAttributes['class'] = 'form-input-select'; break; /* Caso multiselect */ /* Caso multiselect */ case 'multiselect': $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true)); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'form-input-select ms'; $this->aAttributes['multiple'] = 'multiple'; break; /* Caso fileimage */ /* Caso fileimage */ case 'fileimage': $element = new ZendFormElement\File($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); //$this->aAttributes['multiple'] = true; $this->aAttributes['class'] = 'hiddenImageFile'; /* Verifica a pasta de upload */ if (isset($this->formDefaultConfig['pathfiles']) and !empty($this->formDefaultConfig['pathfiles'])) { /* Caso não exista a pasta cria o mesmo */ if (!is_dir(UPLOAD_PATH . $this->formDefaultConfig['pathfiles'])) { mkdir(UPLOAD_PATH . $this->formDefaultConfig['pathfiles'], 0777, true); chmod(UPLOAD_PATH . $this->formDefaultConfig['pathfiles'], 0777); } $this->aAttributes['data-path'] = LINK_DEFAULT . 'uploads/' . $this->formDefaultConfig['pathfiles']; } else { throw new \Exception('Defina a pasta de destino de upload das imagens do editor!', 500); } break; /* Caso file */ /* Caso file */ case 'file': $element = new ZendFormElement\File($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); break; case 'money': $element = new ZendFormElement\Text($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'form-input'; break; /* HTML5 Elements */ /* Caso url */ /* HTML5 Elements */ /* Caso url */ case 'url': $element = new ZendFormElement\Url($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'form-input'; break; /* Caso date */ /* Caso date */ case 'date': $element = new ZendFormElement\Date($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['min'] = date("Y") - 10 . '-01-01'; $this->aAttributes['max'] = date("Y") + 10 . '-12-31'; $this->aAttributes['class'] = 'form-input'; break; case 'dateage': $element = new ZendFormElement\Date($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['min'] = date("Y") - 100 . '-01-01'; $this->aAttributes['max'] = date("Y") + 100 . '-12-31'; $this->aAttributes['class'] = 'form-input'; break; /* Caso time */ /* Caso time */ case 'time': $element = new ZendFormElement\DateTime($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'form-input'; $this->aAttributes['min'] = '00:00:00'; $this->aAttributes['max'] = '23:59:59'; $this->aOptions['format'] = 'H:i:s'; break; /* Caso date */ /* Caso date */ case 'datetime': $element = new ZendFormElement\DateTime($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['min'] = date("Y") - 10 . '-01-01 00:00:00'; $this->aAttributes['max'] = date("Y") + 10 . '-12-31 23:59:59'; $this->aAttributes['class'] = 'form-input'; break; /* Caso email */ /* Caso email */ case 'email': $element = new ZendFormElement\Email($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['class'] = 'form-input'; break; /* Caso number */ /* Caso number */ case 'number': $element = new ZendFormElement\Number($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['step'] = '1'; $this->aAttributes['class'] = 'form-input'; break; case 'integer': $element = new ZendFormElement\Number($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['min'] = '0'; $this->aAttributes['max'] = '99999999999999999999'; $this->aAttributes['step'] = '1'; $this->aAttributes['class'] = 'form-input'; break; case 'float': $element = new ZendFormElement\Number($fieldName); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); $this->aAttributes['step'] = '0.001'; $this->aAttributes['class'] = 'form-input'; break; /* Plataforma */ /* Caso select */ /* Plataforma */ /* Caso select */ case 'status': $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true)); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') { $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder'); } else { $this->selectOptions[''] = "---------"; } $this->aAttributes['class'] = 'form-input-select'; break; /* Caso boolean */ /* Caso boolean */ case 'boolean': $element = new ZendFormElement\Select($fieldName, array('disable_inarray_validator' => true)); $element->setLabel($this->getTranslator($fieldName) . $extraLabel); if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') { $this->selectOptions[''] = $this->getTranslator($fieldName . '_placeholder'); } else { $this->selectOptions[''] = "---------"; } $this->aAttributes['class'] = 'form-input-select'; break; } /* Verifica se foi setado classe de estilo e implementa */ if (isset($fieldParams['class']) and !empty($fieldParams['class'])) { if (isset($this->aAttributes['class']) and $this->aAttributes['class'] != "") { $this->aAttributes['class'] = $this->aAttributes['class'] . " " . $fieldParams['class']; } else { $this->aAttributes['class'] = $fieldParams['class']; } } /* Define a descrição abaixo do campo */ if (isset($fieldParams['description']) and $fieldParams['description'] == 'true') { $this->aOptions['help-block'] = $this->getTranslator($fieldName . '_description'); } /* Verifica se foi setado grupo do campo e implementa */ if (isset($fieldParams['group']) and !empty($fieldParams['group'])) { $this->aOptions['group'] = $fieldParams['group']; } /* Verifica se foi setado placeholder no campo e implementa */ if (isset($fieldParams['placeholder']) and strtolower($fieldParams['placeholder']) == 'true') { $this->aAttributes['placeholder'] = $this->getTranslator($fieldName . '_placeholder'); } /* Verifica se foi setado somente leitura e implementa */ if (isset($fieldParams['readonly']) and strtolower($fieldParams['readonly']) == 'true') { $this->aAttributes['readonly'] = 'readonly'; } /* Verifica se foi setado desabilitado e implementa */ if (isset($fieldParams['disabled']) and strtolower($fieldParams['disabled']) == 'true') { $this->aAttributes['disabled'] = true; } /* Verifica se utilizará mascara no campo */ if (isset($fieldParams['mask']) and !empty($fieldParams['mask'])) { $this->aAttributes['data-inputmask'] = $fieldParams['mask']; } /* Verifica se foi setado inputgroup tipo append e implementa */ if (isset($fieldParams['groupappend']) and !empty($fieldParams['groupappend'])) { $this->aOptions['add-on-append'] = $fieldParams['groupappend']; } /* Verifica se foi setado inputgroup tipo prepend e implementa */ if (isset($fieldParams['groupprepend']) and !empty($fieldParams['groupprepend'])) { $this->aOptions['add-on-prepend'] = $fieldParams['groupprepend']; } /* Verifica se foi setado como array e implementa */ if (isset($fieldParams['array']) and strtolower($fieldParams['array']) == 'true') { $this->aOptions['disable_inarray_validator'] = false; } if (strtolower($fieldParams['type']) !== 'checkbox' and strtolower($fieldParams['type']) !== 'button') { if (strtolower($fieldParams['type']) !== 'textarea' and strtolower($fieldParams['type']) !== 'editor') { //$this->aOptions['column-size'] = 'col4'; } else { //$this->aOptions['column-size'] = 'col6'; } $this->aOptions['labelattributes'] = array('class' => 'form-label'); } else { //$this->aOptions['column-size'] = 'col6 col-sm-offset-2'; unset($this->aOptions['labelattributes']); } return array('element' => $element, 'params' => $fieldParams); }