public function __construct() { if (\Lib\LoginVal::isLogged()) { Location::To(URL . 'user'); } parent::__construct(); $http = new Http(); $this->categories_m = new \models\Categories(); $this->categories = $this->categories_m->getCategories(); $this->products_m = new \models\Products(); $this->d_product = $this->products_m->getDayProduct(); $this->category_ids = $this->categories_m->getCategoriesIds(); if (!$http->isActive('login')) { $this->render('register', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids)); } else { $passVal = new \lib\PassVal("Nieprawidłowe hasło", "Hasła nie są takie same.", 5, 15); $validator = new Validator(array('login' => new \lib\LoginVal("Podana nazwa użytkownika jest zajęta.", "Nieprawidłowa nazaw użytkownika.", 5, 15), 'email' => new \lib\EmailVal("Nieprawidłowy email."), 'password' => $passVal, 'password_2' => $passVal, 'accept' => new \lib\CheckBoxVal("Nie zaznaczono pola z akceptacją regulaminu."))); if ($validator->validate($http->post())) { $this->register($http->post()); $user = new \models\User($this->id); $date = $user->getRegistrationDate(); $subject = 'Aktywacja Konta'; $message = 'W celu aktywowania Konta kliknij <a href="' . URL . 'activation/activate?id=' . $this->id . '®ister=' . $date . '">Tutaj</a>'; $altmessage = 'W celu aktywacji konta odwiedź podany adres:' . URL . 'activation/activate?id=' . $id . '®ister=' . $date; $email = new Email(); if ($email->send($http->post('email'), $subject, $message, $altmessage)) { Location::To(URL . 'success/success/Sprawdź email w celu aktywacji konta.'); } else { Location::To(URL . 'error'); } } else { $this->errors = $validator->getErrors(); $this->render('register', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids, 'errors' => $this->errors)); } } }
// Now we know $key is valid, we can assign it // We use a helper to assist us in the different use cases we can // encounter where the type of input we want to create gives as the value in a format // different than we want to store (e.g. Checkbox gives 'on' and we want to store 1) $value_inserted = DbConversor::convert($form_field->getTypeString(), $var); $response->{$key} = $value_inserted; // We also add it to our parameters array for it to be send to the contact by // e-mail $parameters['fields'][$key] = $value_inserted; // And the field names $parameters['field_names'][$key] = $form_field->field_name; } $response->save(); // Aaaand, we send emails to all the contacts of that form $twig = $app->view()->getEnvironment(); // twig environment $transport = Swift_MailTransport::newInstance(); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $parameters['form'] = $form; foreach ($contacts as $contact) { // Contact to be accessible from the template $parameters['contact'] = $contact; $generator = new Email($twig); $message = $generator->getMessage(Config::read('email_template'), $parameters); $message->setTo($contact->contact_email); $message->setFrom(Config::read('email_from')); $mailer->send($message); } $app->redirect($form->redirect); });