/** * Form initializer * * @param Object $data * @param array $options */ public function initialize($data, $options) { $this->setEntity($data); /** * @var \Phalcon\Translate\Adapter\NativeArray $trans */ $trans = $this->getDI()->getTrans(); $author = array_key_exists('author', $options) ? $options['author'] : $trans->query('common.anonymous'); $application = array_key_exists('application', $options) ? $options['application'] : null; $page_url = array_key_exists('page_url', $options) ? $options['page_url'] : null; $priorities = array(); foreach (['M', 'S', 'C', 'W'] as $p) { $priorities[$p] = $trans->query('priority.' . $p); } $controls = array(); $controls[] = (new Select('priority', $priorities, ['required' => true]))->setDefault('C')->setLabel($trans->query('suggestion.priority'))->addFilter('trim')->addValidators(array(new InclusionIn(array('message' => 'errors.invalid_priority', 'domain' => array_keys($priorities))))); $type_ids = (new XSelect('type_id', SuggestionType::find(), array('using' => array('id', 'name'), 'required' => true, 'useEmpty' => true, 'emptyText' => $trans->query('form.select_from_list'), 'emptyValue' => ''), 'suggestion.'))->setLabel($trans->query('suggestion.type'))->addFilter('trim')->addFilter('int'); $controls[] = $type_ids; $controls[] = (new TextArea('content', ['required' => true, 'maxlength' => 512, 'rows' => 6, 'placeholder' => $trans->query('common.insert_description')]))->setLabel($trans->query('suggestion.content'))->addFilter('trim')->addFilter('null')->addValidators(array(new PresenceOf(array('message' => 'errors.content_is_required')), new StringLength(array('max' => 1000, 'min' => 5, 'messageMaximum' => $trans->query('errors.value_is_too_long'), 'messageMinimum' => $trans->query('errors.value_is_too_short'))))); $controls[] = (new Hidden('page_url', array('value' => $page_url)))->addFilter('trim')->addFilter('null'); $controls[] = (new Hidden('author', array('value' => $author)))->addFilter('trim')->addFilter('title')->addFilter('null'); $controls[] = (new Hidden('application', array('value' => $application)))->addFilter('trim')->addFilter('null'); $controls[] = new Submit('submit', array('value' => $trans->query('form.save'))); foreach ($controls as $control) { $this->add($control); } parent::initialize($data, $options); }
/** * Form initializer * * @param Object $data * @param array $options */ public function initialize($data, $options) { $this->setEntity(new Access()); /** * @var \Phalcon\Translate\Adapter\NativeArray $trans */ $trans = $this->getDI()->getTrans(); $controls[] = (new Text('username', ['required' => true, 'maxlength' => 64, 'placeholder' => $trans->query('user.username')]))->setLabel($trans->query('user.username'))->addFilter('trim')->addFilter('null')->addValidators(array(new PresenceOf(array('message' => 'errors.username_is_required')))); $controls[] = (new Password('password', ['required' => true, 'maxlength' => 64, 'placeholder' => $trans->query('user.password')]))->setLabel($trans->query('user.password'))->addFilter('trim')->addFilter('null')->addValidators(array(new PresenceOf(array('message' => 'errors.password_is_required')))); $controls[] = new Submit('submit', array('value' => $trans->query('user.sign_in'))); foreach ($controls as $control) { $this->add($control); } parent::initialize($data, $options); }
/** * Form initializer * * @param Object $data * @param array $options */ public function initialize($data, $options) { $this->setEntity($data); /** * @var \Phalcon\Translate\Adapter\NativeArray $trans */ $trans = $this->getDI()->getTrans(); $controls[] = (new Text('username', array('required' => true)))->setLabel($trans->query('user.username'))->addFilter('trim')->addFilter('null'); $controls[] = (new Email('email', array('required' => true)))->setLabel($trans->query('user.email'))->addFilter('email'); $controls[] = (new Text('first_name', array('required' => true)))->setLabel($trans->query('user.first_name'))->addFilter('trim')->addFilter('null')->addFilter('title'); $controls[] = (new Text('last_name', array('required' => true)))->setLabel($trans->query('user.last_name'))->addFilter('trim')->addFilter('null')->addFilter('title'); $controls[] = (new TextArea('description', ['required' => true, 'maxlength' => 512, 'rows' => 6, 'placeholder' => $trans->query('common.insert_description')]))->setLabel($trans->query('user.description'))->addFilter('trim')->addFilter('null')->addValidators(array(new PresenceOf(array('message' => 'errors.content_is_required')), new StringLength(array('max' => 512, 'min' => 5, 'messageMaximum' => $trans->query('errors.value_is_too_long'), 'messageMinimum' => $trans->query('errors.value_is_too_short'))))); $controls[] = new Submit('submit', array('value' => $trans->query('form.save'))); foreach ($controls as $control) { $this->add($control); } parent::initialize($data, $options); }