Here’s a mini-tutorial on how I adapted the eForm code to work with Recaptcha. This supercedes the code I referenced above and retains the ability to use the default Captcha code. I think (and dearly hope) this all works as advertised. If others could review, validate or otherwise point out issues, I’d be appreciative. The new code is attached.
Matt
- Create a folder for the recaptcha library, e.g.
assets/snippets/recaptcha
- Upload the recaptchalib.php file provided by recaptcha to the above folder
- Upload the attached recapeform.inc.php to this folder as well
- Put your private and public recaptcha keys in a file called recaptchakeys.php
and upload it to this folder as well. It should look like this
$publickey = "--your public key between these quotes--";
$privatekey = "--your private key between these quotes--";
- Create a copy of the eForm snippet, saving it as "recapeForm"
- Edit this snippet, changing the name of the required include file from "eform.inc.php"
to "recapeform.inc.php" and updating its location as well
- The eForm function name has been changed in this include file to be "recapeForm". So
change the original call to eForm to reflect this name change.
- Create a document with the following content :
[!recapeForm? &vericode=`2` &formid=`testform` &tpl=`testform_chunk` &report=`testformreport_chunk` &gotoid=`2`!]
For no captcha, vericode = 0. For the default captcha, vericode = 1. For Recaptcha, vericode = 2.
- In the chunk that defines the form to be used, add "[+captcha_html+]" in the place
where the recaptcha image/dialogue is supposed to appear. The code for the form I used
to test this is
<p class="error">[+validationmessage+]</p>
<form method="post" action="[~[*id*]~]" id="EmailForm" name="EmailForm">
<fieldset>
<h3> Test Form</h3>
<input name="formid" type="hidden" value="testform" />
<label for="cfName">Your name (required):
<input name="name" id="cfName" class="text" type="text" eform="Your Name::1:" /> </label>
<label for="cfEmail">Your Email Address (required):
<input name="email" id="cfEmail" class="text" type="text" eform="Email Address:email:1" /> </label>
<label for="cfMessage">Message (required):
<textarea name="message" id="cfMessage" rows="4" cols="20" eform="Message:textarea:1"></textarea>
</label>
</fieldset>
[+captcha_html+]
<label> </label><input type="submit" name="contact" id="cfContact" class="button" value="Send This Message" />
</form>
Notes :
- I did not delete any code, but instead put my initials after or around anything
I commented out or added. So to look for changes, search for "MattC"
- The goal here was to avoid stomping on anything that is involved in the released
version of eForm. So some of the above steps would not be needed if in fact one
just wanted to replace eForm with this.
- To allow for a more customized rendition of the recaptcha image, additional
field subsitutions would need to be made, along the lines of the current manner
in which "[+captcha_html+]" is inserted into the form. See lines 710-724. However,
I have not actually tried doing this.
- Not certain what if anything needs to be changed on lines 850-859 and line 998
- When using the default Captcha I did get an "already submitted" message once. But
I wasn’t able to reproduce the error, so I don’t know what happened there.
- I’ve put up a demo at
http://www.considine.net/recaptcha/
No emails will actually get sent from the form, but you should be able to test out
the logic of various types of entries.