Example #1
0
 public function index()
 {
     $contacts = App::getModel('Contact')->getContactToSelect();
     $contactList = App::getModel('Contact')->getContactList();
     $form = new SimpleForm\Form(array('name' => 'contactform', 'action' => '', 'method' => 'post'));
     $form->AddChild(new SimpleForm\Elements\TextField(array('name' => 'firstname', 'label' => _('TXT_FIRSTNAME'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_FIRSTNAME'))))));
     $form->AddChild(new SimpleForm\Elements\TextField(array('name' => 'surname', 'label' => _('TXT_SURNAME'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_SURNAME'))))));
     $form->AddChild(new SimpleForm\Elements\TextField(array('name' => 'email', 'label' => _('TXT_EMAIL'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_EMAIL')), new SimpleForm\Rules\Email(_('ERR_WRONG_EMAIL'))))));
     $form->AddChild(new SimpleForm\Elements\TextField(array('name' => 'phone', 'label' => _('TXT_PHONE'))));
     if ((int) $this->registry->core->getParam() == 0) {
         $form->AddChild(new SimpleForm\Elements\TextField(array('name' => 'topic', 'label' => _('TXT_TOPIC'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_TOPIC'))))));
     }
     $form->AddChild(new SimpleForm\Elements\TextArea(array('name' => 'content', 'label' => _('TXT_CONTENT'), 'rows' => 10, 'cols' => 100, 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_CONTACT_CONTENT'))))));
     $client = App::getModel('client')->getClient();
     if (!empty($client)) {
         $form->Populate(array('firstname' => $client['firstname'], 'surname' => $client['surname'], 'phone' => $client['phone'], 'email' => $client['email']));
     }
     if ($form->Validate()) {
         $formData = $form->getSubmitValues();
         $emails = array($formData['email']);
         if (isset($formData['contactsubject'])) {
             $emails[] = App::getModel('Contact')->getDepartmentMail($formData['contactsubject']);
         }
         $content = $formData['content'];
         if ((int) $this->registry->core->getParam() > 0) {
             $subject = _('TXT_PRODUCT_QUOTE') . ' ' . $this->product['productname'];
             $this->registry->template->assign('productLink', $this->registry->router->generate('frontend.productcart', true, array('param' => $this->product['seo'])));
         } else {
             $subject = $formData['topic'];
         }
         $this->registry->template->assign('CONTACT_CONTENT', $formData['content']);
         $this->registry->template->assign('firstname', $formData['firstname']);
         $this->registry->template->assign('surname', $formData['surname']);
         $this->registry->template->assign('email', $formData['email']);
         $this->registry->template->assign('phone', $formData['phone']);
         App::getModel('mailer')->sendEmail(array('template' => 'contact', 'email' => $emails, 'bcc' => true, 'subject' => $subject, 'viewid' => Helper::getViewId()));
         Session::setVolatileSendContact(1, false);
         App::redirectUrl($this->registry->router->generate('frontend.contact', true));
     }
     $sendContact = Session::getVolatileSendContact();
     if ($sendContact[0] == 1) {
         $this->registry->template->assign('sendContact', _('TXT_CONTACT_SENT'));
     }
     $this->registry->template->assign('form', $form->getForm());
     if ((int) $this->registry->core->getParam() > 0) {
         $this->registry->template->assign('productid', $this->getParam());
     }
     $this->registry->template->assign('content', App::getModel('staticcontent')->getContentByRoute('frontend.contact'));
     $this->registry->template->assign('contactList', $contactList);
     return $this->registry->template->fetch($this->loadTemplate('index.tpl'));
 }