private function _UserStatusId() { $element = new \Phalcon\Forms\Element\Select("UserStatusId"); $element->setLabel("UserStatusId"); $element->setOptions([]); return $element; }
public function initialize() { $keyMap = $this->getUserKeys(); $rendererMap = $this->di->get('renderer')->getRendererNameMap(); $this->add($title = new Text('title')); $this->add(new Text('description')); $this->add($body = new TextArea('body')); $this->add($key = new \Phalcon\Forms\Element\Select('key_id', $keyMap)); $this->add($format = new \Phalcon\Forms\Element\Select('format', $rendererMap)); $key->setDefault($this->user->accountKey_id); $title->addValidator(new \Phalcon\Validation\Validator\PresenceOf(['message' => 'Title is required'])); $body->addValidator(new \Phalcon\Validation\Validator\PresenceOf(['message' => 'Content is required'])); $key->addValidator(new \Phalcon\Validation\Validator\InclusionIn(['message' => 'Encryption key is required', 'domain' => array_keys($keyMap)])); $format->addValidator(new \Phalcon\Validation\Validator\InclusionIn(['message' => 'Format is required', 'domain' => array_keys($rendererMap)])); }
/** * Displays the creation form */ public function newAction() { //SELECT2 $this->importarSelect2(); $select = new \Phalcon\Forms\Element\Select('linea_clienteId', Cliente::find(array('cliente_habilitado=1', 'order' => 'cliente_nombre DESC')), array('using' => array('cliente_id', 'cliente_nombre'), 'useEmpty' => true, 'emptyText' => 'SELECCIONE UN CLIENTE', 'emptyValue' => '', 'class' => 'form-control autocompletar', 'style' => 'width:100%', 'required' => '')); $select->clear(); $this->view->cliente = $select; }
/** * Muestra todas las cabeceras disponibles, para luego buscar sus columnas en obtenerColumnasNombreId. * @param null $planilla_id */ public function editarAction($planilla_id = null) { if ($planilla_id != null) { $this->tag->setDefault('planilla_id', $planilla_id); } $this->assets->collection("headerCss")->addCss('plugins/iCheck/all.css'); $this->assets->collection('headerJs')->addJs('plugins/iCheck/icheck.min.js'); //SELECT2 $this->importarSelect2(); $select = new \Phalcon\Forms\Element\Select('cabecera_id', Cabecera::find(array('cabecera_habilitado=1', 'order' => 'cabecera_id DESC')), array('using' => array('cabecera_id', 'cabecera_nombre'), 'useEmpty' => true, 'emptyText' => 'Seleccione una cabecera', 'emptyValue' => '', 'class' => 'form-control autocompletar', 'style' => 'width:100%', 'required' => '')); $select->clear(); $this->view->formulario = $select; }
protected function _setUpField($field_key, $field_params) { $js_validation = array(); if (isset($field_params[0])) { $field_type = strtolower($field_params[0]); } else { $field_type = 'text'; } if (isset($field_params[1])) { $field_options = (array) $field_params[1]; } else { $field_options = array(); } // Make all field options lower-case. $field_options_new = array(); foreach ($field_options as $field_option_key => $field_option_value) { $field_options_new[strtolower($field_option_key)] = $field_option_value; } $field_options = $field_options_new; // Handle rename of "multiOptions" to "options". if (isset($field_options['multioptions'])) { $field_options['options'] = $field_options['multioptions']; unset($field_options['multioptions']); } // Save for later lookup. $this->fields[$field_key] = array('type' => $field_type) + $field_options; // Clean up array. if (isset($field_options['options'])) { $select_options = $field_options['options']; unset($field_options['options']); } else { $select_options = array(); } if (isset($field_options['label'])) { $element_label = $field_options['label']; unset($field_options['label']); } else { $element_label = NULL; } if (isset($field_options['default'])) { $element_default = $field_options['default']; unset($field_options['default']); } else { $element_default = NULL; } if (isset($field_options['description'])) { unset($field_options['description']); } $element_validators = array(); // Set up file validation options. if ($field_type == 'file') { if (!empty($field_options['maxsize']) || !empty($field_options['allowedtypes'])) { $validate_params = array(); if (!empty($field_options['maxsize'])) { $validate_params['maxsize'] = $field_options['maxsize']; $js_validation['size'] = array('max-size' => $field_options['maxsize']); } if (!empty($field_options['allowedtypes'])) { $validate_params['allowedtypes'] = $field_options['allowedtypes']; $field_options['accept'] = implode(', ', $field_options['allowedtypes']); } if (empty($field_options['required']) || !$field_options['required']) { $validate_params['allowEmpty'] = true; } $element_validators[] = new \Phalcon\Validation\Validator\File($validate_params); unset($field_options['maxsize']); unset($field_options['allowedtypes']); } } if (isset($field_options['required'])) { if ($field_options['required']) { $element_validators[] = new \Phalcon\Validation\Validator\PresenceOf(array('message' => 'This field is required.', 'cancelOnFail' => true)); $js_validation['required'] = array(); } unset($field_options['required']); } if (isset($field_options['validators'])) { foreach ($field_options['validators'] as $validator) { if (!is_string($validator)) { continue; } switch (strtolower($validator)) { case 'emailaddress': case 'email': $element_validators[] = new \Phalcon\Validation\Validator\Email(array('message' => 'This field must be a valid e-mail address.', 'allowEmpty' => true)); $js_validation['email'] = array(); break; case 'webaddress': case 'url': $element_validators[] = new \Phalcon\Validation\Validator\Url(array('message' => 'This field must be a valid web address.', 'allowEmpty' => true)); $js_validation['url'] = array(); break; } } unset($field_options['validators']); } // TODO: Implement filters. if (isset($field_options['filters'])) { unset($field_options['filters']); } // Minimum and Maximum Length Validation if (isset($field_options['minlength']) && isset($field_options['maxlength'])) { $element_validators[] = new \Phalcon\Validation\Validator\StringLength(array('min' => $field_options['minlength'], 'max' => $field_options['maxlength'], 'message' => 'This field must be between ' . $field_options['minlength'] . ' and ' . $field_options['maxlength'] . ' characters.')); $js_validation['length'] = array('length' => $field_options['minlength'] . '-' . $field_options['maxlength']); unset($field_options['minlength'], $field_options['maxlength']); } else { if (isset($field_options['minlength'])) { $element_validators[] = new \Phalcon\Validation\Validator\StringLength(array('min' => $field_options['minlength'], 'message' => 'This field must be at least ' . $field_options['minlength'] . ' characters.')); $js_validation['length'] = array('length' => 'min' . $field_options['minlength']); unset($field_options['minlength']); } else { if (isset($field_options['maxlength'])) { $element_validators[] = new \Phalcon\Validation\Validator\StringLength(array('max' => $field_options['maxlength'], 'message' => 'This field must be less than ' . $field_options['maxlength'] . ' characters.')); $js_validation['length'] = array('length' => 'max' . $field_options['maxlength']); unset($field_options['maxlength']); } } } // Confirmation validation (with another field). if (isset($field_options['confirm'])) { $element_validators[] = new \Phalcon\Validation\Validator\Confirmation(array('with' => $field_options['confirm'])); $js_validation['confirmation'] = array('confirm' => $field_options['confirm']); unset($field_options['confirm']); } // Set up JS validation. if (!empty($js_validation)) { $field_options['data-validation'] = implode(' ', array_keys($js_validation)); foreach ($js_validation as $js_validation_item => $js_validation_options) { if (!empty($js_validation_options)) { foreach ($js_validation_options as $validate_key => $validate_val) { $field_options['data-validation-' . $validate_key] = $validate_val; } } } } // Remove internal classes not needed for render. unset($field_options['belongsto']); unset($field_options['layout']); // Set up element object. switch ($field_type) { case 'password': $element = new \Phalcon\Forms\Element\Password($field_key, $field_options); break; case 'select': $element = new \Phalcon\Forms\Element\Select($field_key, $select_options, $field_options); $validator = new \FA\Forms\Validator\SelectOptionsValidator(array('domain' => Utilities::array_keys_recursive($select_options))); $element->addValidator($validator); break; case 'checkbox': $element = new \Phalcon\Forms\Element\Check($field_key, $field_options); break; case 'checkboxes': case 'multicheckbox': $element = new \FA\Forms\Element\MultiCheckbox($field_key, $select_options, $field_options); $validator = new \FA\Forms\Validator\SelectOptionsValidator(array('domain' => Utilities::array_keys_recursive($select_options))); $element->addValidator($validator); break; case 'radio': $element = new \Phalcon\Forms\Element\Radio($field_key, $field_options); $validator = new \FA\Forms\Validator\SelectOptionsValidator(array('domain' => Utilities::array_keys_recursive($select_options))); $element->addValidator($validator); break; case 'textarea': $element = new \Phalcon\Forms\Element\TextArea($field_key, $field_options); break; case 'hidden': $element = new \Phalcon\Forms\Element\Hidden($field_key, $field_options); break; case 'file': $element = new \FA\Forms\Element\File($field_key, $field_options); break; case 'image': $element = new \FA\Forms\Element\Image($field_key, $field_options); break; case 'date': $element = new \Phalcon\Forms\Element\Date($field_key, $field_options); break; case 'unixdate': $element = new \FA\Forms\Element\UnixDate($field_key, $field_options); break; case 'numeric': $element = new \Phalcon\Forms\Element\Numeric($field_key, $field_options); break; case 'submit': $field_options['value'] = $element_label; $element_label = NULL; $element = new \Phalcon\Forms\Element\Submit($field_key, $field_options); break; case 'markup': $element = new \FA\Forms\Element\Markup($field_key, $field_options['markup'], $field_options); break; case 'captcha': case 'recaptcha': $element = new \FA\Forms\Element\Recaptcha($field_key, $field_options); $validator = new \FA\Forms\Validator\RecaptchaValidator(); $element->addValidator($validator); break; case 'csrf': $element = new \FA\Forms\Element\Csrf($field_key, $field_options); $validator = new \FA\Forms\Validator\CsrfValidator(); $element->addValidator($validator); break; case 'text': default: $element = new \Phalcon\Forms\Element\Text($field_key, $field_options); break; } // Set element label and defaults. $element->setLabel($element_label); $element->setDefault($element_default); // Set up required or min-length validators. if ($element_validators) { $element->addValidators($element_validators); } $this->add($element); return $this; }