/** * Login form component factory. * @return mixed */ protected function createComponentLoginForm() { $form = new AppForm(); $form->addText('username', 'Username:'******'Please provide an username.'); $form->addPassword('password', 'Password:'******'Please provide a password.'); $form->addSubmit('login', 'Login'); $form->addProtection('Please submit this form again (security token has expired).'); /**/ $form->onSubmit[] = array($this, 'loginFormSubmitted'); /**/ /* PHP 5.3 $that = $this; $form->onSubmit[] = function($form) use ($that) { try { $user = Environment::getUser(); $user->authenticate($form['username']->getValue(), $form['password']->getValue()); $that->getApplication()->restoreRequest($that->backlink); $that->redirect('Dashboard:'); } catch (AuthenticationException $e) { $form->addError($e->getMessage()); } };*/ return $form; }
/** * Album delete form component factory. * @return mixed */ protected function createComponentDeleteForm() { $form = new AppForm(); /* PHP 5.3 $that = $this; $form->addSubmit('cancel', 'Cancel')->onClick[] = function() use ($that) { $that->redirect('default'); }; $form->addSubmit('delete', 'Delete')->onClick[] = function() use ($that) { $album = new Albums; $album->delete($that->getParam('id')); $that->flashMessage('Album has been deleted.'); $that->redirect('default'); }; $form['delete']->getControlPrototype()->class('default'); */ /**/ $form->addSubmit('cancel', 'Cancel'); $form->addSubmit('delete', 'Delete')->getControlPrototype()->class('default'); $form->onSubmit[] = array($this, 'deleteFormSubmitted'); /**/ $form->addProtection('Please submit this form again (security token has expired).'); return $form; }
public function createComponentEditForm($table, $id = null) { $form = new AppForm($this, $table . 'EditForm'); $form->addProtection(); if ($id != null) { $form->addHidden('id')->setValue($id); } switch ($table) { case 'students': $years = $this->model('courses')->getYears(); $form->addText('name', 'Name'); $form->addText('surname', 'Surname'); $form->addSelect('year', 'year' . ':', $years); if ($id != null) { $values = $this->model('students')->getStudent($id); } break; case 'teachers': $departments = $this->model('school')->getDepartments(); $form->addText('name', 'Name'); $form->addText('surname', 'Surname'); $form->addSelect('department', 'department' . ':')->setItems($departments, false); if ($id != null) { $values = $this->model('teachers')->getTeacher($id); } break; case 'rooms': $form->addText('name', 'Name'); if ($id != null) { $values = $this->model('school')->getRoom($id); } break; case 'departments': $form->addText('name', 'Name'); if ($id != null) { $values = $this->model('school')->getDepartment($id); } break; case 'learning_times': $form->addText('time', 'time'); if ($id != null) { $values = $this->model('school')->getLearningTime($id); } break; case 'courses': $years = $this->model('courses')->getYears(); $departments = $this->model('school')->getDepartments(); $form->addText('name', 'name'); $form->addSelect('year', 'year:', $years); $form->addSelect('semester', 'semester:', array('L' => 'L', 'Z' => 'Z')); $form->addSelect('department', 'department:', $departments); if ($id != null) { $values = $this->model('courses')->getCourse($id); } break; } $form->addSubmit('btnSubmit', 'Save'); $form->onSubmit[] = array($this, 'editFormSubmitted'); if (isset($values)) { $form->setDefaults($values); } return $form; }