File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 33
44use Cake \Core \Configure ;
55use Cake \Mailer \Mailer ;
6+ use ReCaptcha \ReCaptcha ;
67
78/**
89 * @property \App\Model\Table\ContactsTable $Contacts
@@ -24,12 +25,17 @@ public function rapid()
2425 {
2526 $ this ->autoRender = false ;
2627
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 );
2835
29- if ($ this ->Contacts ->save ($ contact )) {
30- $ this ->sendEmail ($ contact );
31-
32- return ;
36+ return ;
37+ }
38+ }
3339 }
3440
3541 $ this ->response = $ this ->response ->withStatus (422 );
@@ -64,7 +70,7 @@ private function sendEmail($contact)
6470 $ email
6571 ->setEmailFormat ('text ' )
6672 ->setReplyTo ($ contact ->email , $ contact ->name )
67- ->setFrom ([Configure::read ('Site.contact.email ' ) => 'CakeDC Website ' ])
73+ ->setFrom ([Configure::read ('Site.contact.email ' ) => 'CakePHP.org Website ' ])
6874 ->setTo (Configure::read ('Site.contact.email ' ))
6975 ->setSubject ($ contact ->subject )
7076 ->deliver ($ contact ->body );
Original file line number Diff line number Diff line change 66 * @var string $modalId
77 * @var string $secondTitle
88 */
9+
10+ use Cake \Core \Configure ;
11+
912?>
1013<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="<?= $ modalId ?> ">
1114 <div class="modal-dialog" role="document">
127130 </div>
128131 </div>
129132 </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>
130142 </div>
131143
132144 <div class="modal-footer back-modal-footer-show">
You can’t perform that action at this time.
0 commit comments