public function profile() { if ($this->getRequest()->getMethod() == 'POST') { $this->currentUser->setEmail($this->getParam('email')); $this->currentUser->setName($this->getParam('name')); $password = $this->getParam('password', ''); if (!empty($password)) { $this->currentUser->setHash(password_hash($password, PASSWORD_DEFAULT)); } $this->currentUser = $this->userStore->save($this->currentUser); $this->successMessage('Profile updated successfully!'); } $this->setTitle($this->currentUser->getName(), 'Edit Profile'); $form = new \Octo\Admin\Form(); $form->setMethod('POST'); $name = Form\Element\Text::create('name', 'Name', true); $name->setValue($this->currentUser->getName()); $email = Form\Element\Email::create('email', 'Email Address', true); $email->setValue($this->currentUser->getEmail()); $password = Form\Element\Password::create('password', 'Password (enter a new password to change)', false); $submit = new Form\Element\Submit(); $submit->setValue('Update Profile'); $submit->setClass('btn btn-success'); $form->addField($name); $form->addField($email); $form->addField($password); $form->addField($submit); $this->view->form = $form; }
protected function settingsForm($values) { $form = new FormElement(); $form->setMethod('POST'); $fieldset = new FieldSet(); $fieldset->setId('oauth'); $fieldset->setLabel('OAuth Details'); $form->addField($fieldset); $fieldset->addField(Text::create('client_id', 'Client ID')); $fieldset->addField(Text::create('client_secret', 'Client Secret')); if (!empty($values['client_id']) && !empty($values['client_secret'])) { $fieldset = new FieldSet(); $fieldset->setId('login'); $fieldset->setLabel('Google Login'); $form->addField($fieldset); $fieldset->addField(OnOffSwitch::create('login_enabled', 'Enable Google Login?', false)); $fieldset->addField(Text::create('login_auto_create', 'Auto-approved login domains:')); } $submit = new Submit(); $submit->setValue('Save Settings'); $form->addField($submit); return $form; }
protected function userForm($values, $type = 'add') { $form = new FormElement(); $form->setMethod('POST'); if ($type == 'add') { $form->setAction($this->config->get('site.full_admin_url') . '/user/add'); } else { $form->setAction($this->config->get('site.full_admin_url') . '/user/edit/' . $values['id']); } $form->setClass('smart-form'); $fieldset = new Form\FieldSet('fieldset'); $form->addField($fieldset); if (isset($values['id'])) { $field = new Form\Element\Hidden('id'); $field->setRequired(true); $field->setValue($values['id']); $fieldset->addField($field); } $field = new Form\Element\Text('name'); $field->setRequired(true); $field->setLabel('Name'); $fieldset->addField($field); $field = new Form\Element\Email('email'); $field->setRequired(true); $field->setLabel('Email Address'); $fieldset->addField($field); $field = new Form\Element\Password('password'); if ($type == 'add') { $field->setRequired(true); } else { $field->setRequired(false); } $field->setLabel('Password' . ($type == 'edit' ? ' (leave blank to keep current password)' : '')); $fieldset->addField($field); if ($this->currentUser->getIsAdmin()) { $field = new Form\Element\Select('is_admin'); $field->setRequired(false); $field->setLabel('Administrator'); $field->setOptions([0 => 'No', 1 => 'Yes']); $fieldset->addField($field); } $data = [&$form, &$values]; Event::trigger('userForm', $data); list($form, $values) = $data; $fieldset = new Form\FieldSet('fieldset3'); $form->addField($fieldset); $field = new Form\Element\Submit(); $field->setValue('Save User'); $field->setClass('btn-success'); $fieldset->addField($field); $form->setValues($values); return $form; }