本文整理匯總了PHP中Nette\Application\UI\Form::addError方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::addError方法的具體用法?PHP Form::addError怎麽用?PHP Form::addError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Application\UI\Form
的用法示例。
在下文中一共展示了Form::addError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: formSucceeded
/**
* Callback for ForgottenPasswordForm onSuccess event.
* @param Form $form
* @param ArrayHash $values
*/
public function formSucceeded(Form $form, $values)
{
$user = $this->userManager->findByEmail($values->email);
if (!$user) {
$form->addError('No user with given email found');
return;
}
$password = Nette\Utils\Random::generate(10);
$this->userManager->setNewPassword($user->id, $password);
try {
// !!! Never send passwords through email !!!
// This is only for demonstration purposes of Notejam.
// Ideally, you can create a unique link where user can change his password
// himself for limited amount of time, and then send the link.
$mail = new Nette\Mail\Message();
$mail->setFrom('noreply@notejamapp.com', 'Notejamapp');
$mail->addTo($user->email);
$mail->setSubject('New notejam password');
$mail->setBody(sprintf('Your new password: %s', $password));
$this->mailer->send($mail);
} catch (Nette\Mail\SendException $e) {
Debugger::log($e, Debugger::EXCEPTION);
$form->addError('Could not send email with new password');
}
}
示例2: Submit
/** Submit
* @param Form $form
*/
public function Submit(Form $form)
{
$values = $form->getValues();
$contactEntity = new ContactEntity();
$userEntity = new UserEntity();
$contactEntity->setValues((array) $values);
$userEntity->setLogin($values->login);
$userEntity->setAclRoleID(10);
// guest role
$userEntity->setPassword($values->password);
$userEntity->setActive(TRUE);
$contactEntity->setUser($userEntity);
try {
$this->contactRepository->push($contactEntity);
$result = $this->contactRepository->save();
if ($result) {
$this->flashMessage("Vaše registrace proběhla úspěšně.");
$this->redirect('this');
} else {
$form->addError("Vaše registrace neproběhla úspěšně.");
}
} catch (\PDOException $e) {
if (strpos($e->getMessage(), "1062 Duplicate entry") !== FALSE) {
$form->addError("Uživatel {$values->login} již existuje. Zvolte si prosím jiný přihlašovací email.");
} else {
$form->addError($e->getMessage());
}
}
}
示例3: processCreateInvitation
public function processCreateInvitation(Form $form)
{
$value = $form->getValues();
$invitation = new Invitation($value['email'], $this->user->getIdentity());
try {
/** @var EntityResultObject $resultObject */
$resultObject = $this->invitationsFacade->createInvitation($invitation);
$this->flashMessage('Registrační pozvánka byla vytvořena.', 'success');
if (!$resultObject->hasNoErrors()) {
$error = $resultObject->getFirstError();
$this->flashMessage($error['message'], $error['type']);
}
} catch (InvitationCreationAttemptException $ca) {
$this->flashMessage('Pozvánku nebyla vytvořena. Zkuste akci opakovat později.', 'error');
} catch (UserAlreadyExistsException $uae) {
$form->addError('Pozvánku nelze odeslat. Uživatel s E-Mailem ' . $value['email'] . ' je již zaregistrován.');
return;
} catch (InvitationAlreadyExistsException $iae) {
$form->addError('Někdo jiný již odeslal pozvánku uživateli s E-mailem ' . $value['email']);
return;
} catch (DBALException $e) {
$this->flashMessage('Při vytváření pozvánky došlo k chybě. Zkuste akci opakovat později.', 'error');
}
$this->redirect('this');
}
示例4: NfsEditFormValidate
public function NfsEditFormValidate(Form $form, $values)
{
if ($values->export) {
if (preg_match('/\\s/', $values->ips)) {
$form->addError('Pole adres obsahuje mezeru. Jako oddělovač používejte čárku bez mezer, prosím!');
}
$f = $this->folder->find($values->folder_id);
if (!$this->share->checkShare($f->name, $values->ips)) {
$form->addError('Pole adres není validní. Prosím přečtěte si znovu instrukce a zadání opakujte.');
}
}
}
示例5: nastenkaFormValidate
public function nastenkaFormValidate(Form $form, $values)
{
if ($values->platneDo === FALSE && $values->platnostTrvale == FALSE) {
$form->addError('"Zobrazit do" musí být platné datum.');
}
if ($values->platneOd === FALSE) {
$form->addError('"Zobrazit od" musí být platné datum.');
}
if (!$values->platnostTrvale && $values->platneDo !== "") {
if ($values->platneDo < $values->platneOd) {
$form->addError('"Zobrazit od" musí být menší datum než "Zobrazit do".');
}
}
}
示例6: validateAddUserForm
$form->addSubmit('cancel', 'Cancel')->setAttribute('class', 'btn btn-default')->setValidationScope([]);
return $form;
}
/** Vlastná validácia pre AddUserForm
* @param Nette\Application\UI\Form $button
*/
public function validateAddUserForm($button)
{
$values = $button->getForm()->getValues();
if ($button->isSubmitted()->name == 'uloz') {
// Over, ci dane username uz existuje.
if ($this->users->findBy(['username' => $values->username])->count() > 0) {
$button->addError(sprintf('Zadané užívateľské meno %s už existuje! Zvolte prosím iné!', $values->username));
}
// Over, ci dany email uz existuje.
示例7: validateSongsMetadata
public function validateSongsMetadata(Form $form, array $values)
{
$songFiles = $values['song'];
/** @var FileUpload $songFile */
foreach ($songFiles as $songFile) {
if ($songFile->isOk()) {
if (!$this->hasSongValidMetadata($songFile)) {
$form->addError('Song ' . $songFile->getName() . ' has invalid metadata: ' . implode(', ', $this->getInvalidMetadata($songFile)) . '. Upload not permitted.');
}
} else {
$form->addError('Song ' . $songFile->getName() . ' was invalid, upload failed.');
}
}
}
示例8: formSucceeded
/**
* @param Form $form
* @param Nette\Utils\ArrayHash $values
* @return bool
*/
public function formSucceeded(Form $form, $values)
{
if ($this->emailValidator->validate($values->email)) {
$form->addError('Zadaný email je již zaregistrován.');
return FALSE;
} else {
try {
$this->registrator->add($values);
} catch (DuplicateNameException $e) {
$form->addError('Při registraci nastala chyba.');
return FALSE;
}
return TRUE;
}
}
示例9: formSucceeded
public function formSucceeded(Form $form, $values)
{
// pro odchytavani chyb
$error = null;
// ostatni akce
$product = new Model\Product($this->database);
$values['id_user'] = $this->id_user;
$imgs = $values['img'];
unset($values['img']);
// add / edit
if ($values['id'] == null) {
// add
$p = $product->add($values);
$product_id = $p->id;
$form->getPresenter()->flashMessage('Produkt byl úspěšně vytvořen.');
} else {
// edit
$error = $product->update($values, $values['id']);
$product_id = $values['id'];
$form->getPresenter()->flashMessage('Produkt byl úspěšně upraven.');
}
if ($error == null) {
// nahrani fotek k produktu
if ($imgs != null) {
$photo_manager = new Model\Photo($this->database);
$photo_manager->uploadProductPhotos($imgs, $product_id);
}
// presmerovani
$form->getPresenter()->redirect('Homepage:product', $product_id);
} else {
$form->addError($error);
}
}
示例10: processUserRegistration
public function processUserRegistration(Form $form)
{
$values = $form->getValues();
$forbiddenNames = array_flip(['systém', 'system', 'admin', 'administrator', 'administrátor']);
if (array_key_exists(strtolower($values['username']), $forbiddenNames)) {
$form->addError('Vámi zadané jméno nelze použít. Vyberte si prosím jiné.');
return;
}
$values['ip'] = $this->getHttpRequest()->getRemoteAddress();
$values['role'] = 'employee';
$user = new User($values['username'], $values['password'], $values['email'], $values['ip'], $this->invitation->getSender(), $values['role']);
try {
$this->usersFacade->registerNewUser($user, $this->invitation);
$this->flashMessage('Váš účet byl vytvořen. Nyní se můžete přihlásit.', 'success');
$this->redirect('Login:default');
} catch (InvitationValidityException $iu) {
$this->flashMessage('Registrovat se může pouze uživatel s platnou pozvánkou.', 'warning');
$this->redirect('Login:default');
} catch (InvalidUserInvitationEmailException $iue) {
$form->addError('Nesouhlasí Vámi zadaný E-mail a E-mail vázaný na pozvánku.');
} catch (\Exceptions\Runtime\DuplicateUsernameException $du) {
$form->addError('Vámi zvolené jméno využívá již někdo jiný. Vyberte si prosím jiné jméno.');
} catch (\Exceptions\Runtime\DuplicateEmailException $de) {
$this->flashMessage('E-mail svázaný s pozvánkou využívá již jeden z registrovaných
uživatelů. Nechte si zaslat novou pozvánku s jinou E-mailovou adresou.', 'warning');
$this->redirect('Login:default');
} catch (DBALException $d) {
$form->addError('Registraci nelze dokončit. Zkuste to prosím později.');
}
}
示例11: signInFormSucceeded
/**
*
* @param Nette\Application\UI\Form $form
* @throws \Exception
*/
public function signInFormSucceeded($form)
{
$values = $form->getValues();
if ($values->remember) {
$this->user->setExpiration('14 days', FALSE);
} else {
$this->user->setExpiration('20 minutes', TRUE);
}
try {
$user = $this->getActiveUserByUsername($values->username);
if (!$user) {
throw new \Exception('Uživatel není aktivní nebo neexistuje.');
}
$this->user->login($user->username, $values->password);
$this->flashMessage('Byl/a jste úspěšně přihlášen/a jako "' . $user->username . '"', 'success');
if (!empty($values['backSignInUrl'])) {
$redirectToUrl = $values['backSignInUrl'];
} else {
$this->redirect('Homepage:');
}
} catch (Nette\Security\AuthenticationException $e) {
$form->addError($e->getMessage());
} catch (\Exception $e) {
$form->addError($e->getMessage());
}
if (!empty($redirectToUrl)) {
$this->redirectUrl($redirectToUrl);
}
}
示例12: formAddSubmitted
public function formAddSubmitted(\Nette\Application\UI\Form $form)
{
$values = $form->values;
try {
$userRole = $this->em->getRepository('UserRole')->find($values->role);
$values->role = $userRole;
$user = new \Entity\User();
$user->setValues((array) $values);
$this->em->persist($user);
$token = new \Entity\PasswordRecoveryToken();
$token->setUser($user);
$this->em->persist($token);
$this->em->flush();
$this->mailBuilder->buildAccountCreatedEmail($user, $token)->send();
$this->flash(sprintf('User %s added', $user->name));
$this->invalidateControl('grid');
$this->popupOff();
} catch (\PDOException $e) {
switch ($e->getCode()) {
case '23000':
$message = 'Duplicate data';
break;
}
$form->addError($message);
$this->invalidateControl('form');
}
}
示例13: validateForm
/**
* Validace formulare se clankem: datum zverejneni
* @param Form $form
*/
public function validateForm(Form $form)
{
$values = $form->getValues();
if (!empty($values->expiration)) {
$expiration = DateTime::createFromFormat(self::$dateMask, $values->expiration);
$today = new DateTime();
if (!$expiration) {
//neni validni datum
$item = $form->getTranslator()->translate('system.voteExpiration');
$form->addError($form->getTranslator()->translate('system.formFormat', ['item' => $item, 'format' => self::$dateMask]));
} elseif ($expiration < $today) {
$item = $form->getTranslator()->translate('system.voteExpiration');
$form->addError($form->getTranslator()->translate('system.formFormat', ['item' => $item, 'format' => self::$dateMask]));
}
}
}
示例14: signupFormSubmitted
/**
*
* @param Nette\Application\UI\Form $form
*/
public function signupFormSubmitted(Form $form)
{
$formValues = $form->getValues();
$userUsernameRow = $this->userFacade->getByUsername($formValues->username);
$userEmailRow = $this->userFacade->getByEmail($formValues->email);
if ($userUsernameRow !== false || $userEmailRow !== false) {
if ($userUsernameRow !== false) {
$form['username']->addError('This username is already taken. Please use different one.');
}
if ($userEmailRow !== false) {
$form['email']->addError('This email is already taken. Please use different one.');
}
} else {
$hashedPassword = \Screwfix\Authenticator::calculateHash($formValues->password);
$userArr = array('username' => $formValues->username, 'role' => 'member', 'email' => $formValues->email, 'password' => $hashedPassword);
try {
$this->userFacade->save($userArr);
$user = $this->getUser();
if ($formValues->remember) {
$user->setExpiration('+14 days', FALSE);
}
$user->login($formValues->username, $formValues->password);
$pattern = $this->adjustPattern($formValues->patternInput['pattern'], $formValues->patternInput['firstDay']);
$patternFilter = $this->shiftPatternFilterFactory->create($pattern);
$this->patternFacade->save($user->getId(), $patternFilter);
} catch (\Exception $ex) {
$form->addError('Sorry, something went wrong. Please try again.');
}
$this->redirect('Home:default');
}
}
示例15: formSucceeded
public function formSucceeded(Form $form, $values)
{
try {
$user = $this->um->add($values->email, $values->password, $values->name);
if ($user) {
$this->user->login($values->email, $values->password);
$this->onSuccess();
} else {
$form->addError('Oops! Your account could not be created for some reason :-(');
$this->redrawControl('form');
}
} catch (\App\Model\DuplicateEmailException $e) {
$form->addError('Sorry, this email address is already registered. Sign in or use another one.');
$this->redrawControl('form');
}
}