From f61b551cfbd00a5ba8181e3ef022741a6dd9ada3 Mon Sep 17 00:00:00 2001 From: ldrocket Date: Fri, 17 Jul 2015 16:56:26 +0200 Subject: [PATCH 1/3] Add name field to contact form To provide the recipient with the sender's name, add a required name field. If the user is already logged in, the user's name is inputted automatically, depending on the display name setting in admin area (username or real name). --- controllers/contact.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/controllers/contact.php b/controllers/contact.php index 6ee7be1..5d6f3cf 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,30 @@ 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 ( $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 +130,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 +164,4 @@ private function text( $prefix, $key, array $vars = null ) { return OW::getLanguage()->text($prefix, $key, $vars); } -} \ No newline at end of file +} From e5b2642308b028253ecb1e6c99344ffc190b4ad2 Mon Sep 17 00:00:00 2001 From: ldrocket Date: Sun, 19 Jul 2015 14:16:51 +0200 Subject: [PATCH 2/3] Update contact.php Added authentication check in line 76 --- controllers/contact.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/controllers/contact.php b/controllers/contact.php index 5d6f3cf..590d0f0 100644 --- a/controllers/contact.php +++ b/controllers/contact.php @@ -73,13 +73,16 @@ public function index() $fieldName->setLabel($this->text('contactus', 'form_label_name')); // TODO: Add language string in langs.zip $fieldName->setRequired(); - if ( $config->getValue('base', 'display_name_question') == 'username' ) - { - $fieldName->setValue($userService->getUserName($user->getId())); - } - else if ( $config->getValue('base', 'display_name_question') == 'realname' ) + if ( $user->isAuthenticated() ) { - $fieldName->setValue($userService->getDisplayName($user->getId())); + 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); From da04b8ae6cad34b8641205f62d63a526a22427b6 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 24 Jul 2015 19:11:49 +0200 Subject: [PATCH 3/3] Update contact_index.html Add name field --- views/controllers/contact_index.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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'}