Merge pull request #15902 from eileenmcnaughton/transaction_sillyness
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage / ThankYou.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Form to configure thank-you messages and receipting features for an online contribution page.
20 */
21 class CRM_Contribute_Form_ContributionPage_ThankYou extends CRM_Contribute_Form_ContributionPage {
22
23 /**
24 * Set default values for the form.
25 *
26 * Note that in edit/view mode the default values are retrieved from the database.
27 */
28 public function setDefaultValues() {
29 return parent::setDefaultValues();
30 }
31
32 /**
33 * Build the form object.
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);
40
41 $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_text') + ['class' => 'collapsed'];
42 $this->add('wysiwyg', 'thankyou_text', ts('Thank-you Message'), $attributes);
43 $this->add('wysiwyg', 'thankyou_footer', ts('Thank-you Footer'), $attributes);
44
45 $this->addElement('checkbox', 'is_email_receipt', ts('Email Receipt to Contributor?'), NULL, ['onclick' => "showReceipt()"]);
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();
57 $this->addFormRule(['CRM_Contribute_Form_ContributionPage_ThankYou', 'formRule'], $this);
58 }
59
60 /**
61 * Global form rule.
62 *
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.
69 *
70 * @return bool|array
71 * true if no errors, else array of errors
72 */
73 public static function formRule($fields, $files, $options) {
74 $errors = [];
75
76 // if is_email_receipt is set, the receipt message must be non-empty
77 if (!empty($fields['is_email_receipt'])) {
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 /**
88 * Process the form.
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
112 */
113 public function getTitle() {
114 return ts('Thanks and Receipt');
115 }
116
117 }