public function __construct($name = null) { parent::__construct('page'); $id_hidden = new Element\Hidden('id'); $id_hidden->setName('id'); $title_text = new Element\Text('title'); $title_text->setLabel('Title'); $title_text->setLabelAttributes(array('class' => 'type_text type_text_short')); $title_text->setAttributes(array('class' => 'type_text_input', 'placeholder' => 'Type something...', 'required' => 'require')); $url_text = new Element\Text('url'); $url_text->setLabel('Url'); $url_text->setLabelAttributes(array('class' => 'type_text type_text_short')); $url_text->setAttributes(array('class' => 'type_text_input', 'placeholder' => 'Type something...', 'required' => 'require')); $text_textarea = new Element\Textarea('text'); $text_textarea->setLabel('Text'); $text_textarea->setLabelAttributes(array('class' => 'type_text')); $text_textarea->setAttributes(array('placeholder' => 'Type something...')); $auto_check = new Element\Checkbox('auto'); $auto_check->setLabel('Automatically'); $auto_check->setLabelAttributes(array('class' => 'type_text type_check')); $auto_check->setUseHiddenElement(true); $auto_check->setCheckedValue("1"); $auto_check->setUncheckedValue("0"); $auto_check->setValue('1'); $meta_text = new Element\Text('meta'); $meta_text->setLabel('Meta'); $meta_text->setLabelAttributes(array('class' => 'type_text type_text_mod_darker')); $meta_text->setAttributes(array('class' => 'type_text_input')); $keywords_text = new Element\Text('keywords'); $keywords_text->setLabel('Keywords'); $keywords_text->setLabelAttributes(array('class' => 'type_text type_text_mod_darker')); $keywords_text->setAttributes(array('class' => 'type_text_input')); $desc_text = new Element\Text('description'); $desc_text->setLabel('Description'); $desc_text->setLabelAttributes(array('class' => 'type_text type_text_mod_darker')); $desc_text->setAttributes(array('class' => 'type_text_input')); $submit_button = new Element\Submit('submit'); $submit_button->setValue('Submit'); $submit_button->setAttributes(array('class' => 'btn btn_white')); $cancel_button = new Element\Submit('cancel'); $cancel_button->setValue('Cancel'); $cancel_button->setAttributes(array('class' => 'btn btn_rozy')); $this->add($id_hidden); $this->add($title_text); $this->add($url_text); $this->add($text_textarea); $this->add($auto_check); $this->add($meta_text); $this->add($keywords_text); $this->add($desc_text); $this->add($submit_button); $this->add($cancel_button); }
public function __construct() { parent::__construct('loginForm'); $this->setAttributes(array('id' => 'loginForm', 'role' => 'form', 'method' => 'post')); $username = new Element('username'); $username->setLabel('Nombre de Usuario'); $username->setAttributes(array('type' => 'text', 'placeholder' => 'Escribe tu Nombre de Usuario', 'id' => 'username', 'class' => 'form-control')); $password = new Element\Password('password'); $password->setLabel('Contraseña'); $password->setAttributes(array('placeholder' => 'Escribe tu Contraseña', 'id' => 'password', 'class' => 'form-control')); $remember = new Element\Checkbox('remember'); $remember->setLabel('Mantener mi sesión activa'); $remember->setUseHiddenElement(true); $remember->setCheckedValue("1"); $remember->setUncheckedValue("0"); $remember->setAttributes(array('id' => 'remember')); $loginButton = new Element\Button('loginButton'); $loginButton->setLabel('Inicia Sesión'); $loginButton->setAttributes(array('class' => 'btn btn-primary', 'type' => 'submit', 'id' => 'loginButton')); $this->add($username); $this->add($password); $this->add($remember); $this->add($loginButton); }
public function addElements() { //-- Full name -- $full_name = new Element\Text('full_name'); $full_name->setAttribute('placeholder', 'Full Name'); $full_name->setAttribute('class', 'form-control'); $full_name->setAttribute('id', 'full-name'); $full_name->setLabel('Full name'); $full_name->setLabelAttributes(array('class' => 'control-label', 'for' => 'full-name')); //-- Bio -- $bio = new Element\Textarea('bio'); $bio->setAttribute('placeholder', 'Bio'); $bio->setAttribute('class', 'form-control'); $bio->setAttribute('id', 'bio'); $bio->setLabel('Bio'); $bio->setLabelAttributes(array('class' => 'control-label', 'for' => 'bio')); //-- Link skype -- $link_skype = new Element\Text('link_skype'); $link_skype->setAttribute('placeholder', 'skype_name'); $link_skype->setAttribute('class', 'form-control'); $link_skype->setAttribute('id', 'link-skype'); $link_skype->setLabel('Skype'); $link_skype->setLabelAttributes(array('class' => 'control-label', 'for' => 'link-skype')); //-- Link site -- $link_site = new Element\Text('link_site'); $link_site->setAttribute('placeholder', 'http://my-site.com'); $link_site->setAttribute('class', 'form-control'); $link_site->setAttribute('id', 'link-site'); $link_site->setLabel('Link my site'); $link_site->setLabelAttributes(array('class' => 'control-label', 'for' => 'link-site')); //-- Link vkontakte -- $link_vk = new Element\Text('link_vk'); $link_vk->setAttribute('placeholder', 'http://vk.com/user_name'); $link_vk->setAttribute('class', 'form-control'); $link_vk->setAttribute('id', 'link-vk'); $link_vk->setLabel('Link VKontakte'); $link_vk->setLabelAttributes(array('class' => 'control-label', 'for' => 'link-vk')); //-- Link facebook -- $link_fb = new Element\Text('link_fb'); $link_fb->setAttribute('placeholder', 'https://www.facebook.com/user_name'); $link_fb->setAttribute('class', 'form-control'); $link_fb->setAttribute('id', 'link-fb'); $link_fb->setLabel('Link Facebook'); $link_fb->setLabelAttributes(array('class' => 'control-label', 'for' => 'link-fb')); //-- Link twitter -- $link_tw = new Element\Text('link_tw'); $link_tw->setAttribute('placeholder', 'https://twitter.com/user_name'); $link_tw->setAttribute('class', 'form-control'); $link_tw->setAttribute('id', 'link-tw'); $link_tw->setLabel('Link Twitter'); $link_tw->setLabelAttributes(array('class' => 'control-label', 'for' => 'flink-tw')); //-- Password -- $check = new Element\Checkbox('is_active'); $check->setAttribute('class', 'form-control'); $check->setAttribute('id', 'is-active'); $check->setCheckedValue("1"); $check->setUncheckedValue("0"); $check->setLabel('Is active'); $check->setLabelAttributes(array('class' => 'control-label', 'for' => 'is-active')); //-- Submit -- $submit = new Element\Submit('submit'); $submit->setAttribute('class', 'btn btn-success'); $submit->setValue('Send'); // Binding elements $this->add($full_name); $this->add($bio); $this->add($link_skype); $this->add($link_site); $this->add($link_vk); $this->add($link_fb); $this->add($link_tw); $this->add($check); }
/** * 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); }