|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class ContactUsPageControllerExtension extends Extension |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
private static $add_placeholders = false; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
9
|
|
|
'ContactUsForm' => true, |
|
10
|
|
|
'docontactusform' => true |
|
11
|
|
|
); |
|
12
|
|
|
|
|
13
|
|
|
protected $contactUsProcessingForm = false; |
|
14
|
|
|
|
|
15
|
|
|
function ContactUsProcessingForm() { |
|
|
|
|
|
|
16
|
|
|
return $this->contactUsProcessingForm; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
function ContactUsForm() |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
$m = Member::currentUser(); |
|
22
|
|
|
if(!$m) { |
|
23
|
|
|
$m = new Member(); |
|
24
|
|
|
} |
|
25
|
|
|
$fields = new FieldList( |
|
26
|
|
|
TextField::create('FirstName',_t('ContactUsPageControllerExtension.FIRST_NAME', 'First Name'), $m->FirstName), |
|
27
|
|
|
TextField::create('Surname', _t('ContactUsPageControllerExtension.SURNAME', 'Surname'), $m->Surname), |
|
28
|
|
|
EmailField::create('Email',_t('ContactUsPageControllerExtension.EMAIL', 'Email'), $m->Email), |
|
29
|
|
|
TextField::create('Phone', _t('ContactUsPageControllerExtension.PHONE', 'Phone')), |
|
30
|
|
|
TextareaField::create('Enquiry', SiteConfig::current_site_config()->ContactUsFormEnquiryLabel) |
|
31
|
|
|
); |
|
32
|
|
|
if(Config::inst()->get('ContactUsPageControllerExtension', 'add_placeholders')) { |
|
33
|
|
|
foreach($fields as $field) { |
|
34
|
|
|
$field->setAttribute('placeholder', $field->Title()); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
$actions = FieldList::create( |
|
38
|
|
|
FormAction::create('docontactusform', SiteConfig::current_site_config()->ContactUsFormSendLabel) |
|
39
|
|
|
); |
|
40
|
|
|
$form = new Form( |
|
41
|
|
|
$this->owner, |
|
42
|
|
|
'ContactUsForm', |
|
43
|
|
|
$fields, |
|
44
|
|
|
$actions, |
|
45
|
|
|
RequiredFields::create( |
|
46
|
|
|
array("Email", "Enquiry") |
|
47
|
|
|
) |
|
48
|
|
|
); |
|
49
|
|
|
// Update the form to add the protecter field to it |
|
50
|
|
|
|
|
51
|
|
|
return $form; |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function docontactusform ($data, $form) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$data = Convert::raw2sql($data); |
|
58
|
|
|
$obj = ContactUsFormEntry::create_enquiry($data, $this->owner->dataRecord); |
|
59
|
|
|
$subject = _t('ContactUsPageControllerExtension.THANK_YOU_SUBJECT', 'Thank you for your enquiry').' - '.Director::absoluteBaseURL(); |
|
60
|
|
|
$body = "<strong>$subject</strong><br /><br />"; |
|
61
|
|
|
foreach($data as $key => $value) { |
|
|
|
|
|
|
62
|
|
|
if($key == "url") { |
|
63
|
|
|
$value = Director::absoluteURL($value); |
|
64
|
|
|
$value = trim($value, "ContactUsForm"); |
|
65
|
|
|
} |
|
66
|
|
|
if($key == "SecurityID" || $key == "Send" || $key == "Captcha" || $key == 'action_docontactusform') { |
|
|
|
|
|
|
67
|
|
|
//do nothing |
|
68
|
|
|
}else { |
|
69
|
|
|
$body .= "<br /><br />".$key.': '.strip_tags($value).''; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
$adminEmailAddress = SiteConfig::current_site_config()->ContactUsFormEmail; |
|
73
|
|
|
$customerEmailAddress = $data["Email"]; |
|
74
|
|
|
$email = Email::create( |
|
75
|
|
|
$from = $customerEmailAddress, |
|
76
|
|
|
$to = $adminEmailAddress, |
|
77
|
|
|
$subject, |
|
78
|
|
|
$body |
|
79
|
|
|
); |
|
80
|
|
|
$obj->SentToAdmin = $email->send(); |
|
|
|
|
|
|
81
|
|
|
$obj->AdminEmail = $adminEmailAddress; |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$email = Email::create( |
|
84
|
|
|
$from = $adminEmailAddress, |
|
85
|
|
|
$to = $customerEmailAddress, |
|
86
|
|
|
$subject, |
|
87
|
|
|
$body |
|
88
|
|
|
); |
|
89
|
|
|
$obj->SentToCustomer = $email->send(); |
|
|
|
|
|
|
90
|
|
|
$this->contactUsProcessingForm = true; |
|
91
|
|
|
$obj->write(); |
|
92
|
|
|
|
|
93
|
|
|
return array(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.