Fix button breakage on viewContribution
[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
7885e669
MW
23 /**
24 * Set variables up before form is built.
25 */
26 public function preProcess() {
27 parent::preProcess();
28 $this->setSelectedChild('thankyou');
29 }
30
6a488035 31 /**
95cdcc0f 32 * Set default values for the form.
6a488035 33 *
95cdcc0f 34 * Note that in edit/view mode the default values are retrieved from the database.
6a488035 35 */
00be9182 36 public function setDefaultValues() {
6a488035
TO
37 return parent::setDefaultValues();
38 }
39
40 /**
fe482240 41 * Build the form object.
6a488035
TO
42 */
43 public function buildQuickForm() {
44 $this->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
45
46 // thank you title and text (html allowed in text)
47 $this->add('text', 'thankyou_title', ts('Thank-you Page Title'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_title'), TRUE);
2b99bb42 48
be2fb01f 49 $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_text') + ['class' => 'collapsed'];
5d51a2f9
CW
50 $this->add('wysiwyg', 'thankyou_text', ts('Thank-you Message'), $attributes);
51 $this->add('wysiwyg', 'thankyou_footer', ts('Thank-you Footer'), $attributes);
6a488035 52
be2fb01f 53 $this->addElement('checkbox', 'is_email_receipt', ts('Email Receipt to Contributor?'), NULL, ['onclick' => "showReceipt()"]);
6a488035
TO
54 $this->add('text', 'receipt_from_name', ts('Receipt From Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_name'));
55 $this->add('text', 'receipt_from_email', ts('Receipt From Email'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_email'));
56 $this->add('textarea', 'receipt_text', ts('Receipt Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_text'));
57
58 $this->add('text', 'cc_receipt', ts('CC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'cc_receipt'));
59 $this->addRule('cc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
60
61 $this->add('text', 'bcc_receipt', ts('BCC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'bcc_receipt'));
62 $this->addRule('bcc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
63
64 parent::buildQuickForm();
be2fb01f 65 $this->addFormRule(['CRM_Contribute_Form_ContributionPage_ThankYou', 'formRule'], $this);
6a488035
TO
66 }
67
68 /**
fe482240 69 * Global form rule.
6a488035 70 *
014c4014
TO
71 * @param array $fields
72 * The input form values.
73 * @param array $files
74 * The uploaded files if any.
75 * @param array $options
76 * Additional user data.
6a488035 77 *
72b3a70c
CW
78 * @return bool|array
79 * true if no errors, else array of errors
6a488035 80 */
00be9182 81 public static function formRule($fields, $files, $options) {
be2fb01f 82 $errors = [];
6a488035
TO
83
84 // if is_email_receipt is set, the receipt message must be non-empty
a7488080 85 if (!empty($fields['is_email_receipt'])) {
6a488035
TO
86 //added for CRM-1348
87 $email = trim(CRM_Utils_Array::value('receipt_from_email', $fields));
88 if (empty($email) || !CRM_Utils_Rule::email($email)) {
89 $errors['receipt_from_email'] = ts('A valid Receipt From Email address must be specified if Email Receipt to Contributor is enabled');
90 }
91 }
92 return $errors;
93 }
94
95 /**
fe482240 96 * Process the form.
6a488035
TO
97 */
98 public function postProcess() {
99 // get the submitted form values.
100 $params = $this->controller->exportValues($this->_name);
101
102 $params['id'] = $this->_id;
103 $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params, FALSE);
104 if (!$params['is_email_receipt']) {
105 $params['receipt_from_name'] = NULL;
106 $params['receipt_from_email'] = NULL;
107 $params['receipt_text'] = NULL;
108 $params['cc_receipt'] = NULL;
109 $params['bcc_receipt'] = NULL;
110 }
111
112 $dao = CRM_Contribute_BAO_ContributionPage::create($params);
113 parent::endPostProcess();
114 }
115
116 /**
117 * Return a descriptive name for the page, used in wizard header
118 *
119 * @return string
6a488035
TO
120 */
121 public function getTitle() {
122 return ts('Thanks and Receipt');
123 }
96025800 124
6a488035 125}