<?php use Jevets\Kirby\Form; return function ($site, $pages, $page) { $form = new Form(['_token' => ['rules' => ['required', csrf(get('_token'))], 'message' => 'Invalid security token. Please try again.', 'flash' => false], 'name' => ['rules' => ['required'], 'message' => 'Please enter your name'], 'email' => ['rules' => ['required', 'email'], 'message' => 'Please enter your email'], 'phone' => ['rules' => ['required'], 'message' => 'Please enter your phone number'], 'studio' => ['rules' => ['required'], 'message' => 'Please select a studio location'], 'date' => ['rules' => ['required'], 'message' => 'Please specify a date for your party'], 'time' => ['rules' => ['required'], 'message' => 'Please specify a time for your party'], 'type' => [], 'access' => [], 'duration' => [], 'comments' => []]); $types = ['Birthday', 'Anniversary']; $artwork = null; if ($workSlug = get('artwork')) { if ($artworkPage = page("gallery/{$workSlug}")) { $artwork = $artworkPage; } } if (r::is('post')) { if ($form->validates()) { flash('messages.success', "Thanks! We have received your request and will be back in touch very soon!"); $data = $form->data(); if ($artwork) { $data['artwork'] = $artwork; } $studio = page("studios/{$data['studio']}"); event('party.requested', array_merge($data, ['studio' => $studio])); } go($page->url() . '?artwork=' . get('artwork')); } return compact('form', 'types', 'artwork'); };
<?php use Email; use r as Request; use Jevets\Kirby\Form; return function ($site, $pages, $page) { $form = new Form(['name' => ['rules' => ['required'], 'message' => 'Name is required.'], 'email' => ['rules' => ['required', 'email'], 'message' => 'Valid email is required'], 'phone' => [], 'message' => []]); if (Request::is('post')) { if ($form->validates()) { // send an email $body = snippet('emails/contact', $form->data(), true); $email = new Email(['to' => c::get('app.email.to'), 'from' => c::get('app.email.from'), 'subject' => 'Contact Form Submission (' . $form->data('name') . ')', 'replyto' => $form->data('email'), 'body' => $body]); $email->send(); // notify the user flash('messages.success', ["We got your message! We'll be back in touch very soon."]); go('contact'); } else { flash('messages.errors', ["There were errors with your submission..."]); } go($page->url()); } return compact('form'); };
<?php use c as Config; use r as Request; use Jevets\Kirby\Form; return function ($site, $pages, $page) { $form = new Form(['name' => ['rules' => ['required'], 'message' => 'Your name is required'], 'email' => ['rules' => ['required', 'email'], 'message' => 'Your valid email address is required'], 'phone' => ['rules' => ['required'], 'message' => 'Your phone number is required'], 'business_type' => ['rules' => ['required'], 'message' => 'Business type is required'], 'business_name' => ['rules' => ['required'], 'message' => 'Business name is required'], 'business_phone' => ['rules' => ['required'], 'message' => 'Business phone is required'], 'business_address' => ['rules' => ['required'], 'message' => 'Business address is required'], 'business_description' => ['rules' => ['required'], 'message' => 'Business description is required'], 'business_website' => [], 'tripadvisor' => [], 'facebook' => [], 'twitter' => [], 'instagram' => []]); if (Request::is('post')) { if ($form->validates()) { flash('messages.success', ['We got your message.', "We'll be back in touch within a few days after we've reviewed your business.", "If approved we'll request a featured photo from you."]); // save submission $listRequest = new GreenRiverGorge\ListRequest($form->data()); $listRequest->store($page); $to = explode(',', Config::get('email.to')); // notify $email = new \Email(['from' => 'GRG <' . Config::get('email.from') . '>', 'subject' => '[grg] New Listing Request', 'body' => snippet('emails/list-request', $form->data(), true)]); foreach ($to as $recip) { try { $email->send(['to' => $recip]); } catch (\Exception $e) { } } } else { flash('messages.error', ['There were errors with your submission.']); } go($page->url()); } return compact('form'); };