-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintrotodonateform.php
116 lines (107 loc) · 3.48 KB
/
introtodonateform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* @file
* Intro to Donate Form
*
* Extension to store info entered on a mini-form and on submit take you to a donation page populated appropriately.
*
* Copyright (C) 2016, AGH Strategies, LLC <info@aghstrategies.com>
* Licensed under the GNU Affero Public License 3.0 (see LICENSE.txt)
*/
require_once 'introtodonateform.civix.php';
/**
* Implements introtodonateform_civicrm_buildform
*
*/
function introtodonateform_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
if ($form->getAction() == CRM_Core_Action::ADD) {
if (!empty($_GET["itdf-firstname"])) {
$defaults['first_name'] = htmlspecialchars($_GET["itdf-firstname"]);
}
if (!empty($_GET["itdf-lastname"])) {
$defaults['last_name'] = htmlspecialchars($_GET["itdf-lastname"]);
}
if (!empty($_GET["itdf-email"])) {
$defaults['email-5'] = htmlspecialchars($_GET["itdf-email"]);
}
// TODO: make radio buttons change
if (!empty($_GET["itdf-amount"]) && !empty($form->_priceSet['fields'])) {
$found = FALSE;
foreach ($form->_priceSet['fields'] as $field) {
if ($field['name'] == 'contribution_amount') {
$radioId = $field['id'];
}
if (!empty($field['options'])) {
foreach ($field['options'] as $option) {
if (floatval(CRM_Utils_Array::value('itdf-amount', $option)) == floatval($_GET["itdf-amount"])) {
//we found the price option that matches the amount
$defaults['price_' . $field['id']] = $option['id'];
$found = TRUE;
break 2;
}
}
}
if ($field['name'] == 'other_amount') {
$otherId = $field['id'];
}
}
//handle amount not found
if (!$found) {
$defaults['price_' . $radioId] = 0;
$defaults['price_' . $otherId] = $_GET["itdf-amount"];
}
}
$form->setDefaults($defaults);
}
}
}
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function introtodonateform_civicrm_config(&$config) {
_introtodonateform_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function introtodonateform_civicrm_install() {
_introtodonateform_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function introtodonateform_civicrm_enable() {
_introtodonateform_civix_civicrm_enable();
}
/**
* Functions below this ship commented out. Uncomment as required.
*
/**
* Implements hook_civicrm_preProcess().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*
// */
/**
* Implements hook_civicrm_navigationMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
*
function introtodonateform_civicrm_navigationMenu(&$menu) {
_introtodonateform_civix_insert_navigation_menu($menu, NULL, array(
'label' => ts('The Page', array('domain' => 'com.aghstrategies.introtodonateform')),
'name' => 'the_page',
'url' => 'civicrm/the-page',
'permission' => 'access CiviReport,access CiviContribute',
'operator' => 'OR',
'separator' => 0,
));
_introtodonateform_civix_navigationMenu($menu);
} // */