/**
  * Load extra data not from the model into the form
  */
 protected function loadFormData()
 {
     parent::loadFormData();
     $this->loadMailer();
     if (isset($this->formData['gctt'])) {
         $multi = false;
         if (count($this->formData['gctt']) > 1) {
             $multi = true;
             $allLanguages = $this->util->getLocalized()->getLanguages();
         }
         $preview = $this->getPreview($this->formData['gctt']);
         $this->formData['preview_html'] = $preview['html'];
         $this->formData['preview_text'] = $preview['text'];
     }
     if (!isset($this->formData['to'])) {
         $organization = $this->mailer->getOrganization();
         $this->formData['to'] = $this->formData['from'] = null;
         if ($organization->getEmail()) {
             $this->formData['to'] = $this->formData['from'] = $organization->getEmail();
         } elseif ($this->project->getSiteEmail()) {
             $this->formData['to'] = $this->formData['from'] = $this->project->getSiteEmail();
         }
     }
     $this->formData['available_fields'] = $this->mailElements->displayMailFields($this->mailer->getMailFields());
 }
 /**
  * Hook that loads the form data from $_POST or the model
  *
  * Or from whatever other source you specify here.
  */
 protected function loadFormData()
 {
     $presetTargetData = $this->mailer->getPresetTargetData();
     if ($this->request->isPost()) {
         $requestData = $this->request->getPost();
         foreach ($requestData as $key => $value) {
             if (!is_array($value)) {
                 $this->formData[$key] = htmlspecialchars($value);
             } else {
                 $this->formData[$key] = array_map('htmlspecialchars', $value);
             }
         }
     }
     if (empty($this->formData['preview']) && !isset($this->formData['send'])) {
         if (isset($this->formData['select_template']) && !empty($this->formData['select_template'])) {
             if ($template = $this->mailer->getTemplate($this->formData['select_template'])) {
                 $this->formData['subject'] = $template['gctt_subject'];
                 $this->formData['mailBody'] = $template['gctt_body'];
             }
         }
     }
     $this->formData['available_fields'] = $this->mailElements->displayMailFields($this->mailer->getMailFields());
     if (!empty($this->formData['subject']) || !empty($this->formData['mailBody'])) {
         $content = '[b]';
         $content .= $this->_('Subject:');
         $content .= '[/b] [i]';
         $content .= $this->mailer->applyFields($this->formData['subject']);
         $content .= "[/i]\n\n";
         $content .= $this->mailer->applyFields($this->formData['mailBody']);
     } else {
         $content = ' ';
     }
     $htmlView = \MUtil_Html::create()->div();
     $textView = \MUtil_Html::create()->div();
     $htmlView->div(array('class' => 'mailpreview'))->raw(\MUtil_Markup::render($content, 'Bbcode', 'Html'));
     $textView->pre(array('class' => 'mailpreview'))->raw(\MUtil_Markup::render($content, 'Bbcode', 'Text'));
     $this->formData['preview_html'] = $htmlView;
     $this->formData['preview_text'] = $textView;
     $this->formData = array_merge($this->formData, $presetTargetData);
 }