当前位置: 首页>>代码示例>>PHP>>正文


PHP UserForm::isValid方法代码示例

本文整理汇总了PHP中UserForm::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP UserForm::isValid方法的具体用法?PHP UserForm::isValid怎么用?PHP UserForm::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserForm的用法示例。


在下文中一共展示了UserForm::isValid方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: editAction

 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('users', ['action' => 'add']);
     }
     try {
         $user = $this->getUsersTable()->getUser($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('users', ['action' => 'index']);
     }
     $form = new UserForm();
     $form->bind($user);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($user->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getUsersTable()->saveUser($user);
             return $this->redirect()->toRoute('users');
         }
     }
     return ['id' => $id, 'form' => $form];
 }
开发者ID:GlenHughes,项目名称:premiumclans,代码行数:25,代码来源:UsersController.php

示例2: editAction

 /**
  * Allows users to edit another users' data
  * (should be reserved for administrators)
  *
  * @access public
  * @return void
  */
 public function editAction()
 {
     $this->title = 'Edit this user';
     $form = new UserForm();
     $userModel = new BackofficeUser();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             $userModel->save($form->getValues());
             $this->_helper->FlashMessenger(array('msg-success' => 'The user was successfully updated'));
             App_FlagFlippers_Manager::save();
             $this->_redirect('/users/');
         }
     } else {
         $id = $this->_getParam('id');
         if (!is_numeric($id)) {
             $this->_helper->FlashMessenger(array('msg-error' => 'The user id you provided is invalid'));
             $this->_redirect('/users/');
         }
         if ($id == 1) {
             $this->_helper->FlashMessenger(array('msg-error' => 'It is forbidden to mess with the admin account in this release.'));
             $this->_redirect('/users/');
         }
         $row = $userModel->findById($id);
         if (empty($row)) {
             $this->_helper->FlashMessenger(array('msg-error' => 'The requested user could not be found'));
             $this->_redirect('/users/');
         }
         $data = $row->toArray();
         $data['groups'] = $row->groupIds;
         $form->populate($data);
         $this->view->item = $row;
     }
     $this->view->form = $form;
 }
开发者ID:nic162,项目名称:Zend-Framework-Skeleton,代码行数:41,代码来源:UsersController.php

示例3: registerAction

 public function registerAction()
 {
     $user = new User();
     $form = new UserForm($user);
     $form->setFieldsMap(array('PlainPassword' => array(new Limit(null, 255), new NotBlank(), new Password())));
     if ($this->request->isPostMethod()) {
         $form->handleRequest($this->request);
         if ($form->isValid()) {
             $plainPassword = $user->getPlainPassword();
             DB::create($user, $errors);
             if ($this->registry->auth->login($user->Email, $plainPassword)) {
                 FormMessage::sendMessage(FormMessage::SUCCESS, 'Your account is successfully registered.');
                 $this->redirectUrl(BASE_URL . '/profile');
             }
         }
     }
     return array('title' => 'Create Account', 'form' => $form);
 }
开发者ID:rchntrl,项目名称:auth-tt,代码行数:18,代码来源:MainController.php

示例4: editProfileAction

 public function editProfileAction()
 {
     if (!($user = $this->getUser())) {
         exit;
     }
     $form = new UserForm($user);
     if ($this->request->isPostMethod()) {
         $form->handleRequest($this->request);
         if ($form->isValid()) {
             // update record
             DB::update($user);
             FormMessage::sendMessage(FormMessage::SUCCESS, 'Your profile is successfully updated.');
             if ($this->request->getValue('SaveAndExit')) {
                 $this->redirectUrl(BASE_URL . '/profile');
             }
         } else {
             FormMessage::sendMessage(FormMessage::ERROR, 'Sorry, saving went wrong... Try again.');
         }
     }
     return array('title' => 'Edit profile', 'form' => $form);
 }
开发者ID:rchntrl,项目名称:auth-tt,代码行数:21,代码来源:ProfileController.php

示例5: configure

$methods = array('widgetChoiceTableMethod1', 'widgetChoiceTableMethod2', 'widgetChoiceTableMethod3');
foreach ($methods as $method) {
    $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => $method));
    $t->is($widget->getChoices(), array(1 => 1));
}
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => 'widgetChoiceTableMethod4'));
$t->is($widget->getChoices(), array());
$user = new User();
$user->Groups[]->name = 'User Group 1';
$user->Groups[]->name = 'User Group 2';
class UserGroupForm extends GroupForm
{
    public function configure()
    {
        parent::configure();
        $this->useFields(array('name'));
    }
}
$userForm = new UserForm($user);
$userForm->embedRelation('Groups', 'UserGroupForm');
$data = array('username' => 'jonwage', 'password' => 'changeme', 'Groups' => array(0 => array('name' => 'New User Group 1 Name'), 1 => array('name' => 'New User Group 2 Name')));
$userForm->bind($data);
$t->is($userForm->isValid(), true);
if ($userForm->isValid()) {
    $userForm->save();
}
$t->is($user->Groups[0]->name, 'New User Group 1 Name');
$t->is($user->Groups[1]->name, 'New User Group 2 Name');
$form = new DefaultValueTestForm();
$validatorSchema = $form->getValidatorSchema();
$t->is($validatorSchema['name']->getOption('required'), false);
开发者ID:Phennim,项目名称:symfony1,代码行数:31,代码来源:FormTest.php

示例6: newuserAction

 public function newuserAction($idAccount)
 {
     $account = Account::findFirst(array('conditions' => 'idAccount = ?1', 'bind' => array(1 => $idAccount)));
     if (!$account) {
         $this->flashSession->error("No se encuentra la cuenta, por favor valide la información");
         return $this->response->redirect("account");
     }
     $user = new User();
     $form = new UserForm($user, $this->user);
     if ($this->request->isPost()) {
         $form->bind($this->request->getPost(), $user);
         $pass1 = $form->getValue('password1');
         $pass2 = $form->getValue('password2');
         $status = $form->getValue('status');
         if ($this->checkPassword($pass1, $pass2)) {
             $user->idAccount = $account->idAccount;
             $user->password = $this->hash->hash($pass1);
             $user->status = $status;
             $user->created = time();
             $user->updated = time();
             if ($form->isValid() && $user->save()) {
                 $this->flashSession->success("Se ha creado el usuario exitosamente");
                 return $this->response->redirect("account/showusers/{$idAccount}");
             }
             foreach ($user->getMessages() as $msg) {
                 $this->flashSession->error($msg->getMessage());
             }
         }
     }
     $this->view->UserForm = $form;
     $this->view->setVar('account', $account);
 }
开发者ID:solutionsCluster,项目名称:silar,代码行数:32,代码来源:AccountController.php

示例7: editAction

 public function editAction()
 {
     $this->view->title = 'Edit user profile';
     $this->view->messages = $this->_helper->flashMessenger->getMessages();
     $form = new UserForm();
     $this->view->form = $form;
     $userId = $this->_request->getParam('id');
     if ($this->getUser()->getid_uzivatel() !== $userId && !$this->getUser()->isAdmin()) {
         // Redirects
         $this->_helper->redirector->gotoRoute(array('controller' => 'candidate', 'action' => 'index'), 'default', true);
         return;
     }
     if (!empty($userId)) {
         $user = My_Model::get('Users')->getById($userId);
         if ($user !== NULL) {
             $form->setDefaults($user->get_data());
             $avatar = $user->getFoto();
             if ($avatar !== NULL) {
                 $base64 = base64_encode($avatar->getfoto());
                 $form->avatar->setAttrib('src', "data:image/gif;base64," . $base64);
             }
         }
     }
     // ########################### POST ###########################
     // Handles form submission
     if ($this->_request->isPost()) {
         if ($this->_request->getPost('saveButton', false)) {
             if ($form->isValid($this->_request->getPost())) {
                 $formValues = $form->getValues();
                 // Profile photo
                 $photo;
                 if ($form->profilePhoto->isUploaded()) {
                     if (!$form->profilePhoto->receive()) {
                         print "Error receiving the file";
                     }
                     // Reads location and creates blob
                     $profilePhotoLocation = $form->profilePhoto->getFileName();
                     $profilePhotoBlob = file_get_contents($profilePhotoLocation);
                     if (!empty($profilePhotoBlob)) {
                         // Creates photo object
                         $photo = My_Model::get('Photos')->createRow();
                         $photo->foto = $profilePhotoBlob;
                         $photo->nazev = array_pop(explode("/", $profilePhotoLocation));
                         $photo->save();
                     }
                     // Deletes file from directory (is already in DB)
                     unlink($profilePhotoLocation);
                 }
                 // Adds photo id
                 if (!empty($photo)) {
                     $formValues['id_fotografie'] = $photo->getid_foto();
                 }
                 if ($user === NULL) {
                     $user = My_Model::get('Users')->createRow();
                 }
                 if (!empty($formValues["heslo"])) {
                     $formValues["heslo"] = sha1("interview" . $formValues["heslo"]);
                 } else {
                     unset($formValues["heslo"]);
                 }
                 $user->updateFromArray($formValues);
                 $this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'detail', 'id' => $userId), 'default', true);
             }
         } else {
             if ($this->_request->getPost('closeButton', false)) {
                 if (!empty($userId)) {
                     $this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'detail', 'id' => $userId), 'default', true);
                 } else {
                     $this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'index'), 'default', true);
                 }
             } else {
                 if ($this->_request->getPost('deleteButton', false)) {
                     if (!empty($userId)) {
                         My_Model::get('Users')->getById($userId)->delete();
                     }
                     $this->_helper->redirector->gotoRoute(array('controller' => 'user', 'action' => 'index'), 'default', true);
                 }
             }
         }
     }
 }
开发者ID:cngroupdk,项目名称:InterviewMe_Tym1,代码行数:81,代码来源:UserController.php

示例8: editAction

 public function editAction()
 {
     $record = null;
     $photoFilename = null;
     $userId = $this->_request->getParam('id');
     if (!empty($userId)) {
         $record = My_Model::get('Users')->getById($userId);
         if (!$record) {
             throw new Zend_Controller_Action_Exception('The requested page does not exist', 404);
         }
         $this->view->userId = $userId;
     }
     $form = new UserForm();
     $form->setAction($this->_helper->url->url());
     if ($record === null) {
         $this->view->title = 'Add User';
     } else {
         $this->view->title = 'Edit User';
         $form->setModifyMode();
     }
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $formValues = $form->getValues();
             $foundUser = My_Model::get('Users')->fetchRow(array("username = ?" => $formValues["username"]));
             if ($foundUser != null && $foundUser->getId() != $userId) {
                 $form->getElement('username')->addError('This username is taken');
                 $form->markAsError();
                 return;
             }
             //XXX: Je to dobytčárna
             if ($form->photo->receive()) {
                 $photo = $form->photo;
                 $oldFullPath = $photo->getFileName();
                 $path_parts = pathinfo($oldFullPath);
                 if ($path_parts) {
                     $photoFilename = $photo->getHash('md5') . '.' . $path_parts['extension'];
                     $newFullPath = $path_parts['dirname'] . '/' . $photoFilename;
                     rename($oldFullPath, $newFullPath);
                 }
             }
             if ($record === null) {
                 $record = My_Model::get('Users')->createRow();
                 if ($photoFilename) {
                     $record->setPhotoFilename($photoFilename);
                 }
                 $record->updateFromArray($formValues, true);
             } else {
                 if ($photoFilename) {
                     $record->setPhotoFilename($photoFilename);
                 }
                 $record->updateFromArray($formValues, false);
                 //do not update created on value
             }
             //Zend_Debug::dump($formValues);
             //echo '================================================================<br />';
             //Zend_Debug::dump($formValues);
             //echo '========================PHOTO=========================<br />';
             //$var = file_get_contents($form->photo);
             //Zend_Debug::dump($var);
             $this->_helper->flashMessenger->setNamespace("success")->addMessage("Your changes have been saved!");
             $this->_helper->redirector->gotoRoute(array('controller' => 'user'), 'default', true);
         }
     } else {
         if ($record !== null) {
             $form->populate($record->toArray());
         }
     }
 }
开发者ID:cngroupdk,项目名称:InterviewMe_Tym3,代码行数:69,代码来源:UserController.php

示例9: executeUpdate

 public function executeUpdate($request)
 {
     $object = $this->getRequestParameter('object');
     $user = User::getByApiKey($request->getParameter('login_id'), $request->getParameter('api_key'));
     if (!$user) {
         $output = '<rsp stat="fail"><err code="2" msg="login_id and api_key do not match" /></rsp>';
     } elseif ($object == 'application') {
         $form = new ApplicationForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url')));
         if ($form->isValid()) {
             $application = Application::update($form->getValues(), $user);
             if ($application) {
                 $output = '<rsp stat="ok">' . $application->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="4" msg="Unable to update application." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'comment') {
         $form = new CommentForm();
         $application_id = $module_id = $theme_id = null;
         if ($request->getParameter('application_id')) {
             $application_id = $request->getParameter('application_id');
         }
         if ($request->getParameter('module_id')) {
             $module_id = $request->getParameter('module_id');
         }
         if ($request->getParameter('theme_id')) {
             $theme_id = $request->getParameter('theme_id');
         }
         $form->bind(array('comment' => $request->getParameter('comment'), 'application_id' => $application_id, 'module_id' => $module_id, 'theme_id' => $theme_id));
         if ($form->isValid()) {
             $comment = Comment::update($form->getValues(), $user);
             $output = '<rsp stat="ok">' . $comment->getXML() . '</rsp>';
         } else {
             $output = '<rsp stat="fail"><err code="3" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'module') {
         $form = new ModuleForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url'), 'application_id' => $request->getParameter('application_id')));
         if ($form->isValid()) {
             $module = Madule::update($form->getValues(), $user);
             if ($module) {
                 $output = '<rsp stat="ok">' . $module->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="4" msg="Unable to update module." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'theme') {
         $form = new ThemeForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description')), $request->getFiles());
         if ($form->isValid()) {
             $theme = Theme::update($form->getValues(), $user);
             if ($theme) {
                 $output = '<rsp stat="ok">' . $theme->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="5" msg="Unable to update theme." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="5" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'theme_group') {
         $output = '<rsp stat="fail"><err code="6" msg="This object is not supported for update" /></rsp>';
     } elseif ($object == 'user') {
         $form = new UserForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'password' => $request->getParameter('password'), 'password2' => $request->getParameter('password'), 'email' => $request->getParameter('email'), 'role' => null));
         if ($form->isValid()) {
             $update_user = User::update($form->getValues(), $user);
             if ($update_user) {
                 $output = '<rsp stat="ok">' . $update_user->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="7" msg="Unable to update user." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="7" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     }
     $this->output = $output;
     $this->setTemplate('index');
 }
开发者ID:amitesh-singh,项目名称:Enlightenment,代码行数:83,代码来源:actions.class.php

示例10: editprofileAction

 public function editprofileAction()
 {
     $user = $this->user;
     $form = new UserForm($user, $this->user);
     if ($this->request->isPost()) {
         $form->bind($this->request->getPost(), $user);
         $user->updated = time();
         if ($form->isValid() && $user->save()) {
             $this->flashSession->success("Se ha editado el usuario exitosamente");
             return $this->response->redirect("user/editprofile");
         }
         foreach ($user->getMessages() as $msg) {
             $this->flashSession->error($msg);
         }
     }
     $this->view->UserForm = $form;
     $this->view->setVar("user", $user);
 }
开发者ID:solutionsCluster,项目名称:silar,代码行数:18,代码来源:UserController.php


注:本文中的UserForm::isValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。