/**
  * Submit the form
  *
  * @param $data
  * @param $form
  * @return bool|SS_HTTPResponse
  */
 public function Submit($data, $form)
 {
     $recaptchaResponse = $recaptchaResponse = $data['g-recaptcha-response'];
     /** @var Form $form */
     $data = $form->getData();
     /** Set the form state */
     Session::set('FormInfo.Form_' . $this->name . '.data', $data);
     /**
      * reCAPTCHA
      * Based on https://github.com/google/recaptcha
      */
     if ($this->controller->data()->ReCaptchaSiteKey && $this->controller->data()->ReCaptchaSecretKey) {
         $recaptcha = new \ReCaptcha\ReCaptcha($this->controller->data()->ReCaptchaSecretKey);
         $resp = $recaptcha->verify($recaptchaResponse);
         if ($resp->isSuccess()) {
             /**
              * Verified
              */
         } else {
             /**
              * Not Verified
              *
              * @var HTMLText $errors
              */
             $errors = HTMLText::create();
             $html = '';
             /**
              * Error code reference
              * https://developers.google.com/recaptcha/docs/verify
              */
             foreach ($resp->getErrorCodes() as $code) {
                 switch ($code) {
                     case 'missing-input-secret':
                         $html .= _t('ContactForm.RecaptchaMissingInputSecret', 'The secret parameter is missing.');
                         break;
                     case 'invalid-input-secret':
                         $html .= _t('ContactForm.RecaptchaInvalidInputSecret', 'The secret parameter is invalid or malformed.');
                         break;
                     case 'missing-input-response':
                         $html .= _t('ContactForm.RecaptchaMissingInputResponse', 'Please check the reCAPTCHA below to confirm you\'re human.');
                         break;
                     case 'invalid-input-response':
                         $html .= _t('ContactForm.RecaptchaInvalidInputResponse', 'The response parameter is invalid or malformed.');
                         break;
                     default:
                         $html .= _t('ContactForm.RecaptchaDefaultError', 'There was an error submitting the reCAPTCHA, please try again.');
                 }
             }
             $errors->setValue($html);
             $this->controller->setFlash(_t('ContactForm.RecaptchaFormError', 'Your message has not been sent, please fill out all of the <strong>required fields.</strong>'), 'warning');
             $form->addErrorMessage('ReCaptcha', $errors, 'bad', false);
             return $this->controller->redirect($this->controller->Link());
         }
     }
     /** -----------------------------------------
      * Email
      * ----------------------------------------*/
     $data['Logo'] = SiteConfig::current_site_config()->LogoImage();
     $From = $data['Email'];
     $To = $this->controller->data()->MailTo;
     $Subject = SiteConfig::current_site_config()->Title . _t('ContactForm.EmailSubject', ' - Contact message');
     /** @var Email $email */
     $email = Email::create($From, $To, $Subject);
     if ($cc = $this->controller->data()->MailCC) {
         $email->setCc($cc);
     }
     if ($bcc = $this->controller->data()->MailBCC) {
         $email->setBcc($bcc);
     }
     $email->setTemplate('ContactEmail')->populateTemplate($data)->send();
     if ($this->controller->data()->SubmitText) {
         $submitText = $this->controller->data()->SubmitText;
     } else {
         $submitText = _t('ContactForm.SubmitText', 'Thank you for contacting us, we will get back to you as soon as possible.');
     }
     $this->controller->setFlash($submitText, 'success');
     /** -----------------------------------------
      * Records
      * ----------------------------------------*/
     /** @var ContactMessage $contactMessage */
     $contactMessage = ContactMessage::create();
     $form->saveInto($contactMessage);
     $contactMessage->write();
     /** Clear the form state */
     Session::clear('FormInfo.Form_' . $this->name . '.data');
     return $this->controller->redirect($this->controller->data()->Link('?success=1'));
 }