diff --git a/controllers/contact.php b/controllers/contact.php index 6ee7be1..590d0f0 100644 --- a/controllers/contact.php +++ b/controllers/contact.php @@ -52,6 +52,10 @@ public function index() $contactEmails[$contact->id]['label'] = CONTACTUS_BOL_Service::getInstance()->getDepartmentLabel($contact->id); $contactEmails[$contact->id]['email'] = $contact->email; } + + $config = OW::getConfig(); + $userService = BOL_UserSerivce::getInstance(); + $user = OW::getUser(); $form = new Form('contact_form'); @@ -64,15 +68,33 @@ public function index() $fieldTo->setHasInvitation(false); $fieldTo->setLabel($this->text('contactus', 'form_label_to')); $form->addElement($fieldTo); + + $fieldName = new TextField('name'); + $fieldName->setLabel($this->text('contactus', 'form_label_name')); // TODO: Add language string in langs.zip + $fieldName->setRequired(); + + if ( $user->isAuthenticated() ) + { + if ( $config->getValue('base', 'display_name_question') == 'username' ) + { + $fieldName->setValue($userService->getUserName($user->getId())); + } + else if ( $config->getValue('base', 'display_name_question') == 'realname' ) + { + $fieldName->setValue($userService->getDisplayName($user->getId())); + } + } + + $form->addElement($fieldName); $fieldFrom = new TextField('from'); $fieldFrom->setLabel($this->text('contactus', 'form_label_from')); $fieldFrom->setRequired(); $fieldFrom->addValidator(new EmailValidator()); - if ( ow::getUser()->isAuthenticated() ) + if ( $user->isAuthenticated() ) { - $fieldFrom->setValue( OW::getUser()->getEmail() ); + $fieldFrom->setValue( $user->getEmail() ); } $form->addElement($fieldFrom); @@ -111,7 +133,7 @@ public function index() $mail = OW::getMailer()->createMail(); $mail->addRecipientEmail($contactEmails[$data['to']]['email']); - $mail->setSender($data['from']); + $mail->setSender($data['from'], $data['name']); $mail->setSenderSuffix(false); $mail->setSubject($data['subject']); $mail->setTextContent($data['message']); @@ -145,4 +167,4 @@ private function text( $prefix, $key, array $vars = null ) { return OW::getLanguage()->text($prefix, $key, $vars); } -} \ No newline at end of file +} diff --git a/views/controllers/contact_index.html b/views/controllers/contact_index.html index b372806..42f47b1 100644 --- a/views/controllers/contact_index.html +++ b/views/controllers/contact_index.html @@ -13,18 +13,22 @@ {input name='to'}{error name='to'} + {label name='name'} + {input name='name'}{error name='name'} + + {label name='from'} {input name='from'}{error name='from'} - + {label name='subject'} {input name='subject'}{error name='subject'} - + {label name='message'} {input name='message'}{error name='message'} - + {label name='captcha'} {input name='captcha'}{error name='captcha'}