File tree 2 files changed +24
-6
lines changed
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 3
3
4
4
use Cake \Core \Configure ;
5
5
use Cake \Mailer \Mailer ;
6
+ use ReCaptcha \ReCaptcha ;
6
7
7
8
/**
8
9
* @property \App\Model\Table\ContactsTable $Contacts
@@ -24,12 +25,17 @@ public function rapid()
24
25
{
25
26
$ this ->autoRender = false ;
26
27
27
- $ contact = $ this ->Contacts ->createRapidContact ($ this ->getRequest ()->getData ());
28
+ if ($ this ->getRequest ()->is ('post ' )) {
29
+ $ contact = $ this ->Contacts ->createRapidContact ($ this ->getRequest ()->getData ());
30
+ $ recaptcha = new ReCaptcha (Configure::read ('ReCaptcha.secret_key ' ));
31
+ $ resp = $ recaptcha ->verify ($ this ->getRequest ()->getData ('g-recaptcha-response ' ), $ this ->getRequest ()->clientIp ());
32
+ if ($ resp ->isSuccess ()) {
33
+ if ($ this ->Contacts ->save ($ contact )) {
34
+ $ this ->sendEmail ($ contact );
28
35
29
- if ($ this ->Contacts ->save ($ contact )) {
30
- $ this ->sendEmail ($ contact );
31
-
32
- return ;
36
+ return ;
37
+ }
38
+ }
33
39
}
34
40
35
41
$ this ->response = $ this ->response ->withStatus (422 );
@@ -64,7 +70,7 @@ private function sendEmail($contact)
64
70
$ email
65
71
->setEmailFormat ('text ' )
66
72
->setReplyTo ($ contact ->email , $ contact ->name )
67
- ->setFrom ([Configure::read ('Site.contact.email ' ) => 'CakeDC Website ' ])
73
+ ->setFrom ([Configure::read ('Site.contact.email ' ) => 'CakePHP.org Website ' ])
68
74
->setTo (Configure::read ('Site.contact.email ' ))
69
75
->setSubject ($ contact ->subject )
70
76
->deliver ($ contact ->body );
Original file line number Diff line number Diff line change 6
6
* @var string $modalId
7
7
* @var string $secondTitle
8
8
*/
9
+
10
+ use Cake \Core \Configure ;
11
+
9
12
?>
10
13
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="<?= $ modalId ?> ">
11
14
<div class="modal-dialog" role="document">
127
130
</div>
128
131
</div>
129
132
</div>
133
+ <div class="row">
134
+ <div class="col-md-12">
135
+ <div class="fv-row mb-10 mt-10 text-center">
136
+ <div class="g-recaptcha" data-sitekey="<?= Configure::read ('ReCaptcha.site_key ' ) ?> "></div>
137
+ <?php $ this ->Html ->script ('https://www.google.com/recaptcha/api.js ' , ['block ' => true ]); ?>
138
+ <?php $ this ->Form ->unlockField ('g-recaptcha-response ' ); ?>
139
+ </div>
140
+ </div>
141
+ </div>
130
142
</div>
131
143
132
144
<div class="modal-footer back-modal-footer-show">
You can’t perform that action at this time.
0 commit comments