App\Forms\SignInFormFactory::create PHP Method

create() public method

public create ( callable $onSuccess ) : Nette\Application\UI\Form
$onSuccess callable
return Nette\Application\UI\Form
    public function create(callable $onSuccess)
    {
        $form = $this->factory->create();
        $form->addText('username', 'Username:')->setRequired('Please enter your username.');
        $form->addPassword('password', 'Password:')->setRequired('Please enter your password.');
        $form->addCheckbox('remember', 'Keep me signed in');
        $form->addSubmit('send', 'Sign in');
        $form->onSuccess[] = function (Form $form, $values) use($onSuccess) {
            try {
                $this->user->setExpiration($values->remember ? '14 days' : '20 minutes');
                $this->user->login($values->username, $values->password);
            } catch (Nette\Security\AuthenticationException $e) {
                $form->addError('The username or password you entered is incorrect.');
                return;
            }
            $onSuccess();
        };
        return $form;
    }

Usage Example

Example #1
0
 /**
  * @return Nette\Application\UI\Form
  */
 protected function createComponentSignInForm()
 {
     $form = $this->signInFactory->create();
     $form->onSuccess[] = function (Form $form) {
         try {
             $this->user->setExpiration($form->values->remember ? '14 days' : '20 minutes');
             $this->getUser()->login($form->values->username, $form->values->password);
         } catch (AuthenticationException $e) {
             $form->addError($e->getMessage());
         }
         $this->restoreRequest($this->backlink);
         $this->redirect('Homepage:');
     };
     return $form;
 }
All Usage Examples Of App\Forms\SignInFormFactory::create
SignInFormFactory