Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Integrate reCaptcha with PHP form


Go to End


3 Posts   1133 Views

Avatar
Skullies

Community Member, 19 Posts

10 January 2017 at 7:44pm

Hi all
I am having trouble adding the recaptcha spam protection to my form...
It works perfectly on my UserDefinedForm but it is not showing up in any php forms that I create
The code is as follow
//PHP form spam protection added

$form = new Form($this->owner, 'EnquiryForm', $fields, $actions, $validator);
	$form->enableSpamProtection();

How i added the Recaptcha in mysite/_Config/config.yml
FormSpamProtectionExtension:
  default_spam_protector: RecaptchaProtector
RecaptchaField:
  public_api_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  private_api_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

The strange thing is if I use Math Spam protection it shows up but this does not
Can anyone help me with this problem?

Avatar
Kirk

Community Member, 67 Posts

11 January 2017 at 3:54pm

I can not see any issues with the code.
The 2 things I would check is that the relevant spam protection module is installed

https://github.com/chillu/silverstripe-recaptcha

I would also try a dev/build?flush=all as well

Avatar
Skullies

Community Member, 19 Posts

11 January 2017 at 7:33pm

Thanks for the advice Kirk
It turns out that the code was right
I had 2 forms on one page and that duplicated the keys which made the code break