Merge pull request #15902 from eileenmcnaughton/transaction_sillyness
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage / ThankYou.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
07f8d162 19 * Form to configure thank-you messages and receipting features for an online contribution page.
6a488035
TO
20 */
21class CRM_Contribute_Form_ContributionPage_ThankYou extends CRM_Contribute_Form_ContributionPage {
22
23 /**
95cdcc0f 24 * Set default values for the form.
6a488035 25 *
95cdcc0f 26 * Note that in edit/view mode the default values are retrieved from the database.
6a488035 27 */
00be9182 28 public function setDefaultValues() {
6a488035
TO
29 return parent::setDefaultValues();
30 }
31
32 /**
fe482240 33 * Build the form object.
6a488035
TO
34 */
35 public function buildQuickForm() {
36 $this->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
37
38 // thank you title and text (html allowed in text)
39 $this->add('text', 'thankyou_title', ts('Thank-you Page Title'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_title'), TRUE);
2b99bb42 40
be2fb01f 41 $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_text') + ['class' => 'collapsed'];
5d51a2f9
CW
42 $this->add('wysiwyg', 'thankyou_text', ts('Thank-you Message'), $attributes);
43 $this->add('wysiwyg', 'thankyou_footer', ts('Thank-you Footer'), $attributes);
6a488035 44
be2fb01f 45 $this->addElement('checkbox', 'is_email_receipt', ts('Email Receipt to Contributor?'), NULL, ['onclick' => "showReceipt()"]);
6a488035
TO
46 $this->add('text', 'receipt_from_name', ts('Receipt From Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_name'));
47 $this->add('text', 'receipt_from_email', ts('Receipt From Email'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_email'));
48 $this->add('textarea', 'receipt_text', ts('Receipt Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_text'));
49
50 $this->add('text', 'cc_receipt', ts('CC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'cc_receipt'));
51 $this->addRule('cc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
52
53 $this->add('text', 'bcc_receipt', ts('BCC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'bcc_receipt'));
54 $this->addRule('bcc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
55
56 parent::buildQuickForm();
be2fb01f 57 $this->addFormRule(['CRM_Contribute_Form_ContributionPage_ThankYou', 'formRule'], $this);
6a488035
TO
58 }
59
60 /**
fe482240 61 * Global form rule.
6a488035 62 *
014c4014
TO
63 * @param array $fields
64 * The input form values.
65 * @param array $files
66 * The uploaded files if any.
67 * @param array $options
68 * Additional user data.
6a488035 69 *
72b3a70c
CW
70 * @return bool|array
71 * true if no errors, else array of errors
6a488035 72 */
00be9182 73 public static function formRule($fields, $files, $options) {
be2fb01f 74 $errors = [];
6a488035
TO
75
76 // if is_email_receipt is set, the receipt message must be non-empty
a7488080 77 if (!empty($fields['is_email_receipt'])) {
6a488035
TO
78 //added for CRM-1348
79 $email = trim(CRM_Utils_Array::value('receipt_from_email', $fields));
80 if (empty($email) || !CRM_Utils_Rule::email($email)) {
81 $errors['receipt_from_email'] = ts('A valid Receipt From Email address must be specified if Email Receipt to Contributor is enabled');
82 }
83 }
84 return $errors;
85 }
86
87 /**
fe482240 88 * Process the form.
6a488035
TO
89 */
90 public function postProcess() {
91 // get the submitted form values.
92 $params = $this->controller->exportValues($this->_name);
93
94 $params['id'] = $this->_id;
95 $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params, FALSE);
96 if (!$params['is_email_receipt']) {
97 $params['receipt_from_name'] = NULL;
98 $params['receipt_from_email'] = NULL;
99 $params['receipt_text'] = NULL;
100 $params['cc_receipt'] = NULL;
101 $params['bcc_receipt'] = NULL;
102 }
103
104 $dao = CRM_Contribute_BAO_ContributionPage::create($params);
105 parent::endPostProcess();
106 }
107
108 /**
109 * Return a descriptive name for the page, used in wizard header
110 *
111 * @return string
6a488035
TO
112 */
113 public function getTitle() {
114 return ts('Thanks and Receipt');
115 }
96025800 116
6a488035 117}