File: D:/HostingSpaces/SBogers10/ijzerenman.komma.pro/app/Custom/Forms/Types/CallMeBackController.php
<?php
namespace Komma\Forms\Types;
use Komma\Forms\FormController;
class CallMeBackController extends FormController
{
/**
* Show reservation form
*/
public function show()
{
// Get current page entity
$entity = \Current::pageEntity();
$this->formService->setFormName($entity->codeName());
// Get global
list($parent) = $this->pageRepository
->getParents(
$entity->page['lft'],
$entity->page['rgt']
);
// Create dynamic page
$formPage = $this->dynamicPage->createFormFromEntity($entity);
$blocks = $this->dynamicPage->createFromEntity($entity,['page-link-block','file-block','google-maps-block']);
// Render view
$view = \View::make('layouts.pages.callMeBack')
->with([
'entity' => $entity,
'global' => $parent,
'blocks' => $blocks,
'formPage' => $formPage,
'data' => $this->formService->fromSession(),
'bodyClass' => $entity->codeName(),
'successRoute' => $entity->route . '/bedankt-voor-je-verzoek'
])->render();
return $this->renderView($view, $entity);
}
/**
* Process call me back form
*/
public function process()
{
$request = \Request::all();
// Set form name
$this->formService->setFormName($request['formName']);
// Save request in session
$this->formService->saveInSession($request);
// Validate request
if( ! $data = $this->formService->isValid($request))
return \Redirect::back()->withErrors($this->formService->errors());
// Send mail
$data = $this->formService->data($request);
$config = $this->formService->config();
// $this->formMailer->reservationToClient($data,$config);
$this->formMailer->reservationToAdmin($data,$config);
// Set session
\Session::put('success',1);
$this->formService->forgetSession();
// Redirect to thank you page
return \Redirect::to('/' . $request['success_route']);
}
/**
* Show thanks page for reservations
*
* @return mixed
*/
public function success()
{
$formRoute = str_replace('/bedankt-voor-uw-verzoek','',\Route::getCurrentRoute()->uri());
if( ! \Session::has('success')) return \Redirect::to('/' . $formRoute);
\Session::forget('success');
// Get current page entity
$entity = \Current::pageEntity();
$this->formService->setFormName($entity->codeName());
// Get global
list($parent) = $this->pageRepository
->getParents(
$entity->page['lft'],
$entity->page['rgt']
);
// Create dynamic page
$dynamic = $this->dynamicPage->createFormFromEntity($entity);
// Render view
$view = \View::make('layouts.pages.callMeBack')
->with([
'entity' => $entity,
'global' => $parent,
'formPage' => $dynamic,
'data' => $this->formService->fromSession(),
'bodyClass' => $entity->codeName(),
])->render();
return $this->renderView($view, $entity);
}
}