Silverstripe Version: 3.6
I have a contact form on my website which uses reCAPTCHA version 2 to help prevent spam messages. However, quite a few get passed through! How could I stop these? Any help would be greatly appreciated!
Here is my ContactForm.php file:
````<?php
class ContactForm extends Form {
public function __construct(Controller $controller, $name)
{
$emails = array(
'e-mail address here'=>'General',
'e-mail address here'=>'Sales',
'e-mail address here'=>'Technical Support',
);
$fields = FieldList::create(
TextField::create('Name')->setAttribute('placeholder', 'Name'),
EmailField::create('Email')->setAttribute('placeholder', 'Email'),
DropdownField::create('Destination', 'Enquiry', $emails)->setEmptyString("(Department)"),
TextareaField::create('Message')
->setAttribute('placeholder', 'Message')
->setAttribute('rows', 9)
->setAttribute('cols', 25),
LiteralField::create('Captcha', '<div class="g-recaptcha" data-sitekey="MY KEY GOES HERE"></div>')
);
$actions = new FieldList(
FormAction::create('Contact', 'Send')->setAttribute('disabled',true)
);
$validator = new RequiredFields('Name', 'Email', 'Message', 'Destination');
//return Form::create($controller, $name, $fields, $actions, $validator);
parent::__construct($controller, $name, $fields, $actions, $validator);
}
public function Contact($data)
{
$email = new Email();
$email->setFrom($data['Email']);
$email->setSubject("Website Enquiry");
$email->setTo($data['Destination']);
$messageBody = "<p><strong>Name:</strong> {$data['Name']}</p><p><strong>Message:</strong> {$data['Subject']}</p><p><strong>Message:</strong> {$data['Message']}</p>";
$email->setBody($messageBody);
$email->send();
Controller::curr()->redirectBack();
}
}