public function indexAction()
 {
     $data = $this->getRequest()->getPost('data');
     //print_r($this->_fields);
     //create form object
     $form = new Contact_Form_Generic($data, null, $this->_fields, $this->getRequest());
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             $subscription = new Contact_Model_Subscription();
             //exist?
             if (!Contact_Model_SubscriptionMapper::getInstance()->findByEmail($values['email'], $subscription)) {
                 //persist
                 $subscription->setOptions($values);
                 $subscription->set_code(md5(uniqid()))->set_status('pending')->set_lang(CURR_LANG);
                 Contact_Model_SubscriptionMapper::getInstance()->save($subscription);
             }
             $data = $subscription->toArray();
             $data['new_status'] = $values['subscribe'] == 'yes' ? 'subscribed' : 'unsubscribed';
             //set custom email subject
             if ($data['new_status'] == 'unsubscribed' && isset($this->_formParams['email']['subject_respond_un'])) {
                 $this->_formParams['email']['subject_respond'] = $this->_formParams['email']['subject_respond_un'];
             }
             $data['link'] = $this->view->serverUrl() . $this->view->url(array('module' => 'contact', 'controller' => 'subscribe-generic', 'action' => 'status', 'id' => $subscription->get_id(), 'code' => $subscription->get_code(), 'new_status' => $data['new_status'], 'lang' => CURR_LANG));
             //send email
             $this->sendContactEmail($data, $this->_fields, CURR_LANG);
             //sending done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('module' => 'contact', 'controller' => $this->_request->getControllerName(), 'action' => 'landing', 'status' => $data['new_status'])), $this->translate('Thank you for the submission'));
         } else {
             $this->_formHelper->returnError($form->getMessages());
         }
     } else {
         //set default values
         Contact_Form_Generic::setDefaultValues($this->_fields, $data);
     }
     $this->view->data = $data;
     $this->view->fields = $this->_fields;
     $this->view->formParams = $this->_formParams;
     $this->view->formId = $this->_formId;
     if (isset($this->_formParams['template'])) {
         $this->renderScript($this->_formParams['template']);
     }
 }
Пример #2
0
 public function indexAction()
 {
     $data = $this->getRequest()->getPost('data');
     //print_r($this->_fields);
     //create form object
     $form = new Contact_Form_Generic($data, null, $this->_fields, $this->getRequest());
     $entityClassName = $this->getEntityClassName();
     $mapperClassName = $this->getMapperClassName();
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             if ($this->hasFileUpload()) {
                 $this->relocateUploadedFiles($values);
                 $this->_genericFileHelper->pmcCleaner();
             }
             //persist data
             if (isset($this->_formParams['db']['save']) && $this->_formParams['db']['save']) {
                 $contact = new $entityClassName($values);
                 $contact->set_application_id($this->_applicationId)->set_language(CURR_LANG)->set_form_id($this->_formId)->set_posted(HCMS_Utils_Time::timeTs2Mysql(time()));
                 $mapperClassName::getInstance()->save($contact);
             }
             //send email
             $this->sendContactEmail($values, $this->_fields, CURR_LANG);
             //sending done, return success
             return $this->redirectLanding();
         } else {
             $this->_formHelper->returnError($form->getMessages());
         }
     } else {
         //set default values
         Contact_Form_Generic::setDefaultValues($this->_fields, $data);
     }
     $this->view->data = $data;
     $this->view->fields = $this->_fields;
     $this->view->formParams = $this->_formParams;
     $this->view->formId = $this->_formId;
     if (isset($this->_formParams['template'])) {
         $this->renderScript($this->_formParams['template']);
     }
 }