Example #1
0
 /**
  * Validate the form for step 1
  */
 private function validateFormForStep1()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // shorten fields
         $txtName = $this->frm->getField('name');
         $txtFromName = $this->frm->getField('from_name');
         $txtFromEmail = $this->frm->getField('from_email');
         $txtReplyToEmail = $this->frm->getField('reply_to_email');
         $chkGroups = $this->frm->getField('groups');
         $rbtLanguages = $this->frm->getField('languages');
         // validate fields
         if ($txtName->isFilled(BL::err('NameIsRequired'))) {
             if (BackendMailmotorModel::existsMailingByName($txtName->getValue()) && $txtName->getValue() != $this->record['name']) {
                 $txtName->addError(BL::err('MailingAlreadyExists'));
             }
         }
         $txtFromName->isFilled(BL::err('NameIsRequired'));
         $txtFromEmail->isFilled(BL::err('EmailIsRequired'));
         $txtReplyToEmail->isFilled(BL::err('EmailIsRequired'));
         // set form values
         $values = $this->frm->getValues();
         // check if at least one recipient group is chosen
         if (empty($values['groups'])) {
             $chkGroups->addError(BL::err('ChooseAtLeastOneGroup'));
         } else {
             // fetch the recipients for these groups
             $recipients = BackendMailmotorModel::getAddressesByGroupID($values['groups']);
             // if no recipients were found, throw an error
             if (empty($recipients)) {
                 $chkGroups->addError(BL::err('GroupsNoRecipients'));
             }
         }
         // check if at least one language is chosen
         if (empty($values['languages'])) {
             $rbtLanguages->isFilled(BL::err('FieldIsRequired'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // set values
             $item['id'] = $this->id;
             $item['name'] = $txtName->getValue();
             $item['from_name'] = $txtFromName->getValue();
             $item['from_email'] = $txtFromEmail->getValue();
             $item['reply_to_email'] = $txtReplyToEmail->getValue();
             $item['language'] = $rbtLanguages->getValue();
             $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
             if (isset($values['campaign']) && (!empty($values['campaign']) || $values['campaign'] == 0)) {
                 $item['campaign_id'] = $this->frm->getField('campaign')->getValue();
             }
             // update the concept
             BackendMailmotorModel::updateMailing($item);
             // update groups for this mailing
             BackendMailmotorModel::updateGroupsForMailing($this->id, $values['groups']);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step1', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&step=2');
         }
     }
 }