Ejemplo n.º 1
0
 /**
  * @return Form
  */
 public function create()
 {
     $form = new Form();
     if ($this->translator) {
         $form->setTranslator($this->translator);
     }
     return $form;
 }
Ejemplo n.º 2
0
 protected function createComponentProcess()
 {
     $form = new Form();
     $form->addText('text', 'Text');
     $form->onProcess[] = $this->process;
     $form->onProcess[] = $this->processSecond;
     $form->onProcess[] = $this->processThird;
     return $form;
 }
Ejemplo n.º 3
0
 /**
  * @param Form $form
  * @param ArrayHash $values
  */
 public function successSignIn(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->email, $values->password);
     } catch (BadPasswordException $e) {
         $form->addError($form->getTranslator()->translate($e->getMessage()));
     } catch (UserNotFoundException $e) {
         $form->addError($form->getTranslator()->translate($e->getMessage()));
     }
 }
Ejemplo n.º 4
0
 /**
  * @param WebChemistry\Forms\Form $form
  * @param object $values
  */
 public function successForm(WebChemistry\Forms\Form $form, $values)
 {
     if ($form->getSubmittedName() === 'preview') {
         $explode = explode('___', $form->getName());
         $class = str_replace('_', '\\', $explode[0]);
         $method = $explode[1];
         $class = $this->provider->getByClass($class);
         $preview = $class->showPreview($method);
         $preview->setContent($values->template);
         $preview->setPreview();
         $this->template->html = (string) $preview;
         if ($preview->hasError()) {
             $this->flashMessage('emails.admin.default.variableNotExists', 'error');
         }
     } else {
         $explode = explode('___', $form->getName());
         $class = str_replace('_', '\\', $explode[0]);
         $method = $explode[1];
         $class = $this->provider->getByClass($class);
         /** @var WebChemistry\Emails\Templating\Engine $template */
         $template = call_user_func($class->getCallback($method));
         $store = $template->read();
         $template->getLocalFile()->rewriteSafe($values->template);
         @unlink($template->getCacheFile());
         $template->renderToString();
         if ($template->hasError()) {
             $template->getLocalFile()->rewriteSafe($store);
             $this->flashMessage('emails.admin.default.variableNotExists', 'error');
             return;
         }
         // Other
         $class->setData($method, $form->getValues(TRUE));
         $this->flashMessage('emails.admin.default.successForm');
         $this->redraw();
     }
 }
Ejemplo n.º 5
0
 public function testResetEventsParameters()
 {
     $form = new Form();
     $form->onSuccess[] = function () {
     };
     $form->onSuccess[] = function () {
     };
     $form->onSubmit[] = function () {
     };
     $form->onError[] = function () {
     };
     $form->onError[] = function () {
     };
     $form->resetEvents(['onSuccess', 'onSubmit']);
     $this->assertSame(array(), $form->onSuccess);
     $this->assertSame(array(), $form->onSubmit);
     $this->assertCount(2, $form->onError);
 }