/** * Wrapper for flash object to be used as global function. * * @param string $message - message text * @param string $type - message type: success, info, warning, error * @param TemplateInterface $template - template (optional) * * @return Flash */ function flash($message = '', $type = 'info', TemplateInterface $template = null) { $flash = new Flash($template); if (!empty($message)) { return $flash->message($message, $type); } return $flash; }
public static function save_place() { $flash = new Flash(); $post_data = Flight::request()->data; // recaptcha $secret = getenv('RECAPTCHA_SECRET'); $gRecaptchaResponse = $post_data['g-recaptcha-response']; $recaptcha = new ReCaptcha($secret); $resp = $recaptcha->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']); if ($resp->isSuccess()) { // verified! $address = "{$post_data['calle']} {$post_data['altura']}, {$post_data['ciudad']}, {$post_data['provincia']}, Argentina"; // save new place Place::create(array('name' => $post_data['name'], 'address' => $address, 'start_hour' => $post_data['start_hour'], 'end_hour' => $post_data['end_hour'], 'days' => $post_data['days'], 'comments' => $post_data['comments'])); $flash->message('success'); } else { $errors = $resp->getErrorCodes(); $flash->message('error'); } Flight::redirect('/', 302); }