/** * Displays the form and handles the user input. * * @author Christian Schäfer * @version * Version 0.1, 03.06.2006<br /> * Version 0.2, 04.06.2006<br /> * Version 0.3, 29.03.2007<br /> * Version 0.4, 27.05.2007<br /> * Version 0.5, 12.09.2009 (Refactoring due to changes of the form tags)<br /> */ public function transformContent() { $form = $this->getForm('contact'); // fill recipient list /* @var $recipients SelectBoxTag */ $recipients = $form->getFormElementByName('recipient'); /* @var $cM ContactManager */ $cM = $this->getServiceObject(ContactManager::class); $recipientList = $cM->loadRecipients(); for ($i = 0; $i < count($recipientList); $i++) { $recipients->addOption($recipientList[$i]->getName(), $recipientList[$i]->getId()); } if ($form->isSent() && $form->isValid()) { $formData = new ContactFormData(); $option = $recipients->getSelectedOption(); $recipientId = $option->getValue(); $formData->setRecipientId($recipientId); $name = $form->getFormElementByName('sender-name'); $formData->setSenderName($name->getAttribute('value')); $email = $form->getFormElementByName('sender-address'); $formData->setSenderEmail($email->getAttribute('value')); $subject = $form->getFormElementByName('subject'); $formData->setSubject($subject->getAttribute('value')); $text = $form->getFormElementByName('content'); $formData->setMessage($text->getContent()); $cM->sendContactForm($formData); } else { $form->transformOnPlace(); } }
/** * Sends the contact form and displays the thanks page. * * @param ContactFormData $formData The form's content. * * @author Christian Schäfer * @version * Version 0.1, 03.06.2006<br /> * Version 0.2, 04.06.2006<br /> * Version 0.3, 21.06.2006 (Now an additional mail is sent to the sender)<br /> * Version 0.4, 09.03.2007<br /> * Version 0.5, 31.03.2007<br /> * Version 0.6, 04.01.2008 (Corrected url generating for non-rewrite urls)<br /> */ public function sendContactForm(ContactFormData $formData) { // set up the mail sender /* @var $mail mailSender */ $mail = $this->getServiceObject(mailSender::class); $mail->init('ContactForm'); /* @var $recipient ContactFormRecipient */ $recipient = $this->getMapper()->loadRecipientById($formData->getRecipientId()); $mail->setRecipient($recipient->getEmailAddress(), $recipient->getName()); $mail->setContent($this->getNotificationText(['sender-name' => $formData->getSenderName(), 'sender-email' => $formData->getSenderEmail(), 'sender-subject' => $formData->getSubject(), 'sender-message' => $formData->getMessage(), 'recipient-name' => $recipient->getName(), 'recipient-email' => $recipient->getEmailAddress()])); $mail->setSubject($formData->getSubject()); // send mail to notify the recipient $mail->sendMail(); $mail->clearRecipients(); $mail->clearCCRecipients(); $mail->clearContent(); $mail->setRecipient($formData->getSenderEmail(), $formData->getSenderName()); $mail->setContent($this->getConfirmationText(['sender-name' => $formData->getSenderName(), 'sender-email' => $formData->getSenderEmail(), 'sender-subject' => $formData->getSubject(), 'sender-message' => $formData->getMessage(), 'recipient-name' => $recipient->getName(), 'recipient-email' => $recipient->getEmailAddress()])); $mail->setSubject($formData->getSubject()); // send mail to notify the sender $mail->sendMail(); // redirect to the thanks page to avoid F5 bugs! $link = LinkGenerator::generateUrl(Url::fromCurrent()->mergeQuery(['contactview' => 'thanks'])); $this->getResponse()->forward($link); }