Exemplo n.º 1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // 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');
         // validate fields
         if ($txtName->isFilled(BL::err('NameIsRequired'))) {
             if (in_array($txtName->getValue(), $this->group['custom_fields'])) {
                 $txtName->addError(BL::err('CustomFieldExists'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             try {
                 // add the new item to the custom fields list
                 $this->group['custom_fields'][] = $txtName->getValue();
                 // set the group fields by flipping the custom fields array for this group
                 $groupFields = array_flip($this->group['custom_fields']);
                 // group custom fields found
                 if (!empty($groupFields)) {
                     // loop the group fields and empty every value
                     foreach ($groupFields as &$field) {
                         $field = '';
                     }
                 }
                 // addresses found and custom field delete with CM
                 BackendMailmotorCMHelper::createCustomField($txtName->getValue(), $this->group['id']);
                 // update custom fields for this group
                 BackendMailmotorModel::updateCustomFields($groupFields, $this->group['id']);
             } catch (\Exception $e) {
                 // redirect with a custom error
                 $this->redirect(BackendModel::createURLForAction('CustomFields') . '&group_id=' . $this->group['id'] . '&error=campaign-monitor-error&var=' . urlencode($e->getMessage()));
             }
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('CustomFields') . '&group_id=' . $this->group['id'] . '&report=added&var=' . urlencode($txtName->getValue()) . '&highlight=id-' . $this->group['id']);
         }
     }
 }