/**
  * Returns the appropriate response up the controller chain
  * if {@link validate()} fails (which is checked prior to executing any form actions).
  * By default, returns different views for ajax/non-ajax request, and
  * handles 'application/json' requests with a JSON object containing the error messages.
  * Behaviour can be influenced by setting {@link $redirectToFormOnValidationError}.
  *
  * @return SS_HTTPResponse|string
  */
 protected function getValidationErrorResponse()
 {
     $request = $this->getRequest();
     if ($request->isAjax()) {
         // Special case for legacy Validator.js implementation
         // (assumes eval'ed javascript collected through FormResponse)
         $acceptType = $request->getHeader('Accept');
         if (strpos($acceptType, 'application/json') !== FALSE) {
             // Send validation errors back as JSON with a flag at the start
             $response = new SS_HTTPResponse(Convert::array2json($this->validator->getErrors()));
             $response->addHeader('Content-Type', 'application/json');
         } else {
             $this->setupFormErrors();
             // Send the newly rendered form tag as HTML
             $response = new SS_HTTPResponse($this->forTemplate());
             $response->addHeader('Content-Type', 'text/html');
         }
         return $response;
     } else {
         if ($this->getRedirectToFormOnValidationError()) {
             if ($pageURL = $request->getHeader('Referer')) {
                 if (Director::is_site_url($pageURL)) {
                     // Remove existing pragmas
                     $pageURL = preg_replace('/(#.*)/', '', $pageURL);
                     $pageURL = Director::absoluteURL($pageURL, true);
                     return $this->controller->redirect($pageURL . '#' . $this->FormName());
                 }
             }
         }
         return $this->controller->redirectBack();
     }
 }
 /**
  * Executes the main functionality of the output processor
  *
  * @param \Controller $controller The relevant SilverStripe controller
  * @param mixed $result The result from the input processor
  * @return mixed|null
  */
 public function process(\Controller $controller, $result = null)
 {
     if ($controller->getRequest()->isAjax()) {
         $response = $controller->getResponse();
         $response->setStatusCode(200);
         $response->addHeader('Content-Type', 'application/json');
         $response->setBody(json_encode($result));
         return $response;
     } else {
         $controller->redirectBack();
     }
     return null;
 }
 /**
  * Invoke a batch action
  *
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  */
 public function handleBatchAction($request)
 {
     // This method can't be called without ajax.
     if (!$request->isAjax()) {
         return $this->parentController->redirectBack();
     }
     // Protect against CSRF on destructive action
     if (!SecurityToken::inst()->checkRequest($request)) {
         return $this->httpError(400);
     }
     // Find the action handler
     $action = $request->param('BatchAction');
     $actionHandler = $this->actionByName($action);
     // Sanitise ID list and query the database for apges
     $csvIDs = $request->requestVar('csvIDs');
     $ids = $this->cleanIDs($csvIDs);
     // Filter ids by those which are applicable to this action
     // Enforces front end filter in LeftAndMain.BatchActions.js:refreshSelected
     $ids = $actionHandler->applicablePages($ids);
     // Query ids and pass to action to process
     $pages = $this->getPages($ids);
     return $actionHandler->run($pages);
 }
 /**
  * @param \Controller $controller
  * @param mixed|void        $result
  * @return void
  */
 public function process(\Controller $controller, $result = null)
 {
     if ($result['Success']) {
         if (isset($result['Complete']) && $result['Complete']) {
             $controller->redirect($this->completeURL);
             return;
         } else {
             $controller->redirect($this->confirmationURL);
             return;
         }
     }
     if (isset($result['CheckFailure']) && $result['CheckFailure']) {
         $controller->redirectBack();
     } else {
         $controller->redirect($this->failureURL);
     }
     return;
 }
 public function SendContactForm($data, $form)
 {
     if ($this->SubmitText) {
         $SubmitText = $this->SubmitText;
     } else {
         $SubmitText = "Your email is on it\\'s way. Thanks for contacting us!";
     }
     if (trim(strtolower($data['Spam'])) != 'hot') {
         $form->sessionMessage('Please give that spam question another try.', 'bad');
         Controller::redirectBack();
     } else {
         $From = $data['Email'];
         $To = $this->Mailto;
         $Subject = "Contact form submission from the contact form widget";
         $email = new Email($From, $To, $Subject);
         $email->setTemplate('ContactFormEmail');
         $email->populateTemplate($data);
         $email->send();
         $form->sessionMessage($SubmitText, 'success');
         Controller::redirectBack();
     }
 }