Beispiel #1
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = array();
     $submit = false;
     $values = $this->request->getGPAsArray();
     if ($this->request->post('mailform')) {
         $submit = true;
         $required = $values['required'];
         $fields = $values['field'];
         $this->validation->setData($fields);
         $this->validation->addRule('email', 'email');
         $errorMessages = array();
         foreach ($required as $field => $val) {
             $this->validation->addRule($field, 'notEmpty');
             $errorMessages = array_merge($errorMessages, array($field => array($field => $this->translation->getTranslation('Please fill out the field'))));
         }
         $this->validation->setErrorMessages($errorMessages);
         $check = $this->validation->check();
         if ($check === true) {
             $msg = $this->mail->getMessageInstance();
             $msg->setFrom(array($fields['email']));
             $msg->setSubject($this->config->get('MAILFORM_SUBJECT')->value);
             $msg->setTo(explode(',', $this->config->get('MAILFORM_TO')->value));
             $this->template->assign('fields', $fields);
             $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
             $this->mail->send();
         } else {
             $errors = $check;
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }
Beispiel #2
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = [];
     $submit = false;
     $values = $this->request->getGPAsArray();
     $requiredFields = $this->getRequiredFields($xml);
     $formHash = $this->createFormHash($requiredFields);
     if ($this->request->post('mailform')) {
         $required = $values['required'];
         $fields = $values['field'];
         if ($this->isFormValid($formHash, $this->getValidationRules($required))) {
             $submit = true;
             $this->validation->setData($fields);
             $this->validation->addRule('email', 'email');
             $errorMessages = [];
             foreach ($requiredFields as $field => $val) {
                 $this->validation->addRule($field, $val['rule'], $val['param']);
                 $errorMessages = array_merge($errorMessages, [$field => [$field => $this->translation->getTranslation('Please fill out the field')]]);
             }
             $this->validation->setErrorMessages($errorMessages);
             $check = $this->validation->check();
             if ($check === true) {
                 $config = json_decode($xml->mailformOptions, true);
                 $receiver = $config[$this->locale->getLocale()->id]['email'];
                 $subject = $config[$this->locale->getLocale()->id]['subject'];
                 $msg = $this->mail->getMessageInstance();
                 $msg->setFrom([$fields['email']]);
                 $msg->setSubject($subject);
                 $msg->setTo(explode(',', $receiver));
                 $this->template->assign('fields', $fields, false);
                 $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
                 $this->mail->send();
             } else {
                 $errors = $check;
             }
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }