/**
  * Sign up new user
  */
 public function postSignupAction()
 {
     $post = $this->request->getPost()->all();
     $validation = new Validation();
     $validation->rules(['name' => 'required', 'email' => 'required|email|unique:users']);
     $valid = $validation->validate($post);
     if (!$valid) {
         echo 'Warning! Please correct the errors:<br />';
         foreach ($validation->getMessages() as $message) {
             echo $message[0] . '<br />';
         }
     } else {
         $user = new Users();
         $user->setFields(['name', 'email']);
         if ($user->create($post)) {
             echo "Thanks for registering!";
         }
     }
     $this->view->setContent(false);
 }
 /**
  * Validate _POST and send email
  *
  * @throws Error
  */
 public function postContactAction()
 {
     $validation = new Validation();
     $validation->rules(['fullName' => 'required', 'email' => 'required|email', 'repeatEmail' => 'same:email', 'content' => 'required|length:10,5000']);
     $valid = $validation->validate($_POST);
     if (!$valid) {
         $this->view->setVar('errors', $validation->getMessages());
         $this->flash->warning(_t('flash/warning/errors'));
     } else {
         // Prepare an email
         $email = new Email();
         $email->prepare(_t('contact'), $this->config->app->admin, 'email/contact', ['fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content')]);
         $email->addReplyTo($this->request->getPost('email'));
         // Try to send email
         if ($email->Send() === true) {
             $this->flash->success(_t('flash/success/contact'));
             unset($_POST);
         } else {
             throw new Error($email->ErrorInfo);
         }
     }
 }
Exemple #3
0
 public function validationAction()
 {
     $data = ['emailAddress' => '', 'repeatEmailAddress' => '*****@*****.**'];
     $validation = new Validation();
     $validation->setHumanLabels(true);
     // $validation->rule('emailAddress', new Required());
     // $validation->rule('emailAddress', new Email());
     // $validation->rule('repeatEmailAddress', new Same(['other' => 'emailAddress']));
     // $validation->rules([
     //     'emailAddress' => [
     //         new Required(),
     //         new Email()
     //     ],
     //     'repeatEmailAddress' => new Same(['other' => 'emailAddress'])
     // ]);
     $validation->rules(['emailAddress' => ['required', 'email'], 'repeatEmailAddress' => ['same' => ['other' => 'emailAddress', 'message' => ':field must be the same as :other', 'label' => 'Repeat E-mail', 'labelOther' => 'E-mail']]]);
     // $validation->rules([
     //     'emailAddress' => 'required|email',
     //     'repeatEmailAddress' => 'same:emailAddress'
     // ]);
     $validation->validate($data);
     if (!$validation->valid()) {
         $messages = $validation->getMessages();
     }
     var_dump($messages->all());
     // $data = [
     //     'username' => 'ice123_framework'
     // ];
     // $validation = new Validation();
     // $validation->setFilters([
     //     'username' => 'alpha'
     // ]);
     // $validation->validate($data);
     // var_dump($validation->getValue('username'));
     $this->app->setAutoRender(false);
 }