|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This class can be used by controllers in your project to set up a basic sign up |
|
5
|
|
|
* form. |
|
6
|
|
|
* |
|
7
|
|
|
* You can test it in isolation using the SalesForceExamplesSignupController class. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
class SalesForceSignupForm extends Form |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
14
|
|
|
'doSalesForceSignUp' => true |
|
15
|
|
|
]; |
|
16
|
|
|
|
|
17
|
|
|
private static $based_on_instance_of = 'SalesForceContact'; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Our constructor only requires the controller and the name of the form |
|
21
|
|
|
* method. We'll create the fields and actions in here. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct($controller, $name) |
|
25
|
|
|
{ |
|
26
|
|
|
$fields = $this->getBaseFields(); |
|
27
|
|
|
|
|
28
|
|
|
$actions = $this->getBaseAction(); |
|
29
|
|
|
|
|
30
|
|
|
$required = $this->getBaseRequiredFields(); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
// now we create the actual form with our fields and actions defined |
|
33
|
|
|
// within this class |
|
34
|
|
|
parent::__construct($controller, $name, $fields, $actions, $required); |
|
35
|
|
|
|
|
36
|
|
|
// any modifications we need to make to the form. |
|
37
|
|
|
$this->loadDataFrom($_REQUEST); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
public function setSigupFields(array $fieldArray) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$newList = new FieldList(); |
|
44
|
|
|
$oldFields = $this->Fields(); |
|
45
|
|
|
foreach($fieldsArray as $field) { |
|
|
|
|
|
|
46
|
|
|
$newField = $oldFields->dataFieldByName($field); |
|
47
|
|
|
$newList->push($newField); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->setFields($newList); |
|
51
|
|
|
|
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function setRequiredFields(array $fieldArray) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->setRequiredFields(new RequiredFields($fieldArray)); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function setFormSubmitText(string $label) |
|
64
|
|
|
{ |
|
65
|
|
|
$newFields = new FieldList( |
|
66
|
|
|
FormAction::create('doSalesForceSignUp', $label) |
|
67
|
|
|
); |
|
68
|
|
|
$this->setActions($newFields); |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function getBaseFields() |
|
74
|
|
|
{ |
|
75
|
|
|
$newInstanceClassName = Config::inst()->get('SalesForceSignupForm', 'based_on_instance_of'); |
|
76
|
|
|
$newInstance = $newInstanceClassName::create(); |
|
77
|
|
|
|
|
78
|
|
|
return $newInstance->getFrontEndFields(); |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function getBaseAction() |
|
83
|
|
|
{ |
|
84
|
|
|
return new FieldList( |
|
85
|
|
|
FormAction::create('doSalesForceSignUp', 'Register') |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function getBaseRequiredFields() |
|
90
|
|
|
{ |
|
91
|
|
|
new RequiredFields( |
|
92
|
|
|
[ |
|
93
|
|
|
'FirstName', |
|
94
|
|
|
'LastName', |
|
95
|
|
|
'Email', |
|
96
|
|
|
] |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
public function doSalesForceSignUp($data, Form $form) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
MySalesForcePartnerAPI::create_contact($data); |
|
104
|
|
|
die('We need the option here to set a redirection link AND/OR provide an AJAX response'); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|