本文整理汇总了PHP中Nette\Application\UI\Form类的典型用法代码示例。如果您正苦于以下问题:PHP Form类的具体用法?PHP Form怎么用?PHP Form使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Form类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToFormContainer
/**
* Adds text field to filter form
* @param Nette\Application\UI\Form $form
*/
public function addToFormContainer($form)
{
$form->addText($this->key, $this->name);
if ($this->getPlaceholder()) {
$form[$this->key]->setAttribute('placeholder', $this->getPlaceholder());
}
}
示例2: 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');
}
示例3: FtpEditFormValidate
public function FtpEditFormValidate(Form $form, $values)
{
$eqUsername = $this->share->findAll()->where('shareType_id = ?', self::shareType_id)->where('NOT folder_id = ?', $values->folder_id)->where('var = ?', $values->username)->fetchAll();
if ($eqUsername) {
$form->addError('Toto přihlašovací jméno už existuje, zvolte prosím jiné.');
}
}
示例4: formEditSave
/**
* Process a directive edit form.
* @param void
*/
public function formEditSave(Form $form)
{
$data = $form->getValues();
$this->id = $data->id;
$this->title = $data->title;
$this->date = $data->date;
$this->change = $data->change;
$this->revision = $data->revision;
$oldName = $this->document;
$this->setDocument();
try {
$this->row->update(array('id' => $this->id, 'title' => $this->title, 'date' => $this->date, 'change' => $this->change, 'revision' => $this->revision, 'document' => $this->document));
if ($oldName) {
$this->renameDocFile($oldName, $this->document);
}
foreach ($this->getComponents(FALSE, "Annex") as $annex) {
$annex->id = $this->id;
$annex->updateData();
}
$this->presenter->flashMessage('Směrnice byla aktualizována.', 'success');
$this->redirect('this');
} catch (Nette\Application\AbortException $e) {
throw $e;
} catch (Exception $ex) {
if ($ex->getCode() == 23000) {
$this->presenter->flashMessage('Zadané číslo směrnice již existuje. ', 'error');
$this->handleEdit();
}
}
}
示例5: signInFormSubmitted
public function signInFormSubmitted(Form $form)
{
try {
$user = $this->getUser();
$values = $form->getValues();
/*if ($values->persistent) {
$user->setExpiration('+30 days', FALSE);
}*/
/** make login */
$user->login($values->username, $values->password);
/** get rights */
$userId = $user->getIdentity()->id;
$permissions = array();
foreach ($this->permissionRepository->getLevels($userId)->fetchPairs('url') as $page => $level) {
$permissions[$page] = $level->level;
}
/** test for admin */
$permissions['admin'] = $this->userRepository->isAdmin($userId);
/** set permissions */
$user->getIdentity()->setRoles($permissions);
$this->flashMessage('Přihlášení bylo úspěšné.', 'success');
$this->redirect('Homepage:');
} catch (Nette\Security\AuthenticationException $e) {
$form->addError('Neplatné uživatelské jméno nebo heslo.');
}
}
示例6: create
/** @return Form */
public function create()
{
$f = new Form();
$f->addText('text')->setRequired('TRUE')->setAttribute('placeholder', 'Vyhledat');
$f->addSubmit('submit', 'Vyhledat')->setAttribute('class', 'btn btn-primary');
return $f;
}
示例7: formSucceeded
/**
* Callback for Account Settings Form onSuccess event.
* @param Form $form
* @param ArrayHash $values
*/
public function formSucceeded(Form $form, $values)
{
if (!$this->userManager->checkPassword($this->user->getId(), $values->current)) {
$form->addError("Invalid current password");
}
$this->userManager->setNewPassword($this->user->getId(), $values->new);
}
示例8: create
public function create()
{
$form = new Form();
$form->getElementPrototype()->addClass('form-horizontal');
$form->setRenderer(new Bs3FormRenderer());
return $form;
}
示例9: create
/**
* @return \Nette\Application\UI\Form
*/
public function create()
{
$form = new Form();
$form->addGroup($this->user ? 'Upravit uživatele' : 'Přidat uživatele');
$form->addText("name", 'Jméno:')->setRequired('Vyplňte jméno');
$form->addText("email", 'Email:')->setRequired('Vyplňte email')->addRule(function ($ctrl) {
if ($this->user and $this->user->email == $ctrl->getValue()) {
return TRUE;
}
return (bool) (!$this->userFacade->findUserByEmail($ctrl->getValue()));
}, 'Email je obsazen, zvolte prosím jiný');
$password = $form->addPassword("password", 'Heslo:');
$password2 = $form->addPassword("password2", 'Heslo znovu:');
if (!$this->user) {
$password->setRequired('Vyplňte heslo');
$password2->addRule(Form::FILLED, 'Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password);
} else {
$password2->addConditionOn($password, Form::FILLED)->setRequired('Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password);
}
$form->addSubmit("send", $this->user ? 'Upravit uživatele' : 'Přidat uživatele');
$form->setRenderer(new Bs3FormRenderer());
$form->onSuccess[] = $this->processForm;
if ($this->user) {
$form->setDefaults(["name" => $this->user->name, "email" => $this->user->email]);
}
return $form;
}
示例10: 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');
}
}
示例11: createComponentLogInForm
/**
* LogIn-in form factory.
* @return Nette\Application\UI\Form
*/
protected function createComponentLogInForm()
{
$form = new Nette\Application\UI\Form();
$form->setTranslator($this->translator->domain('ui'));
$form->addText('username', 'login-username')->setRequired('please-enter-your-username')->setAttribute('autofocus');
$form->addPassword('password', 'login-password')->setRequired('');
$form->addCheckbox('remember', 'keep-me-signed-in');
$form->addSubmit('send', 'log-in');
$form->onSuccess[] = $this->logInFormSucceeded;
// setup form rendering for Twitter Bootstrap
$renderer = $form->getRenderer();
$renderer->wrappers['controls']['container'] = NULL;
$renderer->wrappers['pair']['container'] = 'div class=form-group';
$renderer->wrappers['pair']['.error'] = 'has-error';
$renderer->wrappers['control']['container'] = 'div class=col-sm-3';
$renderer->wrappers['label']['container'] = 'div class="col-sm-3 control-label"';
$renderer->wrappers['control']['description'] = 'span class=help-block';
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
// make form and controls compatible with Twitter Bootstrap
$form->getElementPrototype()->class('form-horizontal');
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = TRUE;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
return $form;
}
示例12: create
public function create() : Form
{
$form = new Form();
$form->addText('value')->addRule($form::FILLED);
$form->onSuccess[] = [$this, 'process'];
return $form;
}
示例13: 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.');
}
}
示例14: createComponentAddSetting
protected function createComponentAddSetting()
{
$form = new Form();
$form->addText('key', 'Klíč')->setRequired('Zadejte klíč nastavení');
$form->addText('value', 'Hodnota')->setRequired('Zadejte hodnotu nastavení');
$form->addSubmit('send', 'Zapsat');
$form->onSuccess[] = function (Form $f) {
try {
$val = $f->values;
$this->settings->set($val->key, $val->value);
$this->settings->push();
//Write
$this->logger->log('System', 'edit', "%user% změnila(a) nastavení");
$msg = $this->flashMessage("Nastavení bylo zapsáno", 'success');
$msg->title = 'Yehet!';
$msg->icon = 'check';
$this->redirect('this');
} catch (\PDOException $e) {
\Nette\Diagnostics\Debugger::log($e);
$msg = $this->flashMessage("Něco se podělalo. Zkuste to prosím později.", 'danger');
$msg->title = 'Oh shit!';
$msg->icon = 'warning';
}
};
return $form;
}
示例15: uspesne
public function uspesne(Form $form, $hodnoty)
{
$zaznam = $this->database->table('druhZivocicha')->get($this->Id);
$zaznam->update($hodnoty);
$form->getPresenter()->flashMessage('Úspešne editované!', 'uspech');
$form->getPresenter()->redirect('Druh:viac', $this->Id);
}