public function SubmitServiceAreasForm($data, $form)
 {
     // magical spam protection
     if (!FormUtilities::validateAjaxCode()) {
         Session::set("FormInfo.ServiceAreasForm_ServiceAreasForm.data", $data);
         $form->addErrorMessage("Message", "Error, please enable javascript to use this form", "bad");
         return $this->redirectBack();
     }
     $SAPage = $this->getPointer();
     // save submission for posterity
     $submission = new ServiceAreasFormSubmission();
     $submission->ServiceAreasPageID = $SAPage->ID;
     $submission->FirstName = $data['FirstName'];
     $submission->LastName = $data['LastName'];
     $submission->Address = $data['Address'];
     $submission->Address2 = $data['Address2'];
     $submission->City = $data['City'];
     $submission->State = $data['State'];
     $submission->ZipCode = $data['ZipCode'];
     $submission->Email = $data['Email'];
     $submission->Phone = $data['Phone'];
     $submission->Comments = $data['Comments'];
     $submission->PageURL = $_SERVER['HTTP_REFERER'];
     $submission->Date = SS_Datetime::now();
     $submission->write();
     // send email to this address if specified
     $emails = $SAPage->FormRecipients();
     if ($emails) {
         foreach ($emails as $email) {
             $EmailFormTo = $email->Email;
             FormUtilities::SendSSEmail($this, $EmailFormTo, $data, $submission);
         }
     }
     // redirect to our thank you page
     $this->redirect($this->Link("/thanks/"));
 }
 public function SubmitForm($data, $form)
 {
     $form_config = $this->FormConfig();
     // magical spam protection
     if (!FormUtilities::validateAjaxCode() && $form_config['useNospam']) {
         Session::set("FormInfo.Form_RenderForm.data", $data);
         Session::set("FormError", "Error, please enable javascript to use this form.");
         return $this->redirectBack();
     }
     $submission_class = $this->ClassName . "Submission";
     $submission = new $submission_class();
     $form->saveInto($submission);
     $submission->FormPageID = $this->ID;
     $submission->write();
     $form_config = $this->FormConfig();
     // send email to this address if specified
     if ($form_config['sendToAll']) {
         $EmailFormTo = $this->FormRecipients()->toArray();
     } else {
         $EmailFormTo = $this->FormRecipients()->filter(array("Title" => $data['Recipient']));
     }
     $utils = new FormUtilities();
     // Email to site Admin
     if ($EmailFormTo) {
         foreach ($EmailFormTo as $email) {
             $utils->SendSSEmail($this, $email->Email, $data, $submission);
         }
     }
     if (($as = $this->AutoResponderSubject) && ($ab = $this->AutoResponder)) {
         $utils->SendAutoResponder($as, $ab, $data['Email']);
     }
     $this->extend('onAfterSubmit', $submission);
     if ($form_config['PageAfterSubmit']) {
         $page = $this->ClassName . "_" . $form_config['PageAfterSubmit'];
         return $this->customise($data)->renderWith(array($page, 'Page'));
     }
     return $this->redirect($this->Link('thanks'));
 }