Permalink
Browse files

first basic support for recaptcha field in forms

  • Loading branch information...
nsams committed Dec 23, 2013
1 parent cc2a117 commit 780969d7cb9c9e0a0af67f09e3a9e3d200b91a7b
@@ -11,5 +11,6 @@ protected function _init()
->setVtype('email')
->setWidth(300);
$this->fields['content']->setFieldLabel(trlKwfStatic('Comment'));
$this->insertAfter('content', new Kwf_Form_Field_Recaptcha('captcha', trlKwfStatic('Captcha')));
}
}
@@ -0,0 +1,43 @@
<?php
class Kwf_Form_Field_Recaptcha extends Kwf_Form_Field_Abstract
{
public function validate($row, $postData)
{
$ret = parent::validate($row, $postData);
$sess = new Kwf_Session_Namespace('recaptcha');
if ($sess->validated) {
//if user did solve one captcha we store that in session and don't annoy him again
return $ret;
}
require_once(Kwf_Config::getValue('externLibraryPath.recaptcha').'/recaptchalib.php');
$resp = recaptcha_check_answer (Kwf_Config::getValue('recaptcha.privateKey'),
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$msg = $resp->error;
if ($msg == 'incorrect-captcha-sol') {
$msg = trlKwf('Please solve captcha correctly');
}
$ret[] = array(
'message' => $msg,
'field' => $this
);
} else {
$sess->validated = true;
}
return $ret;
}
public function getTemplateVars($values, $fieldNamePostfix = '', $idPrefix = '')
{
$ret = parent::getTemplateVars($values, $fieldNamePostfix, $idPrefix);
require_once(Kwf_Config::getValue('externLibraryPath.recaptcha').'/recaptchalib.php');
$ret['html'] = "<div data-fieldname=\"".$this->getFieldName().$fieldNamePostfix."\">"
.recaptcha_get_html(Kwf_Config::getValue('recaptcha.publicKey'))
."</div>";
return $ret;
}
}
@@ -0,0 +1,7 @@
Kwf.FrontendForm.Recaptcha = Ext.extend(Kwf.FrontendForm.Field, {
getFieldName: function() {
return this.el.child('div[data-fieldname]').dom.getAttribute('data-fieldname');
}
});

Kwf.FrontendForm.fields['kwfFormFieldRecaptcha'] = Kwf.FrontendForm.Recaptcha;
@@ -36,6 +36,7 @@ externLibraryPath.file = %libraryPath%/file/5.11
externLibraryPath.aws = %libraryPath%/aws/1.5.14
externLibraryPath.sass = %libraryPath%/sass/20130424-ead0ac1897
externLibraryPath.htmLawed = %libraryPath%/htmLawed/1.1.14
externLibraryPath.recaptcha = %libraryPath%/recaptcha/1.11
includepath.phpunit = %libraryPath%/phpunit/3.4.0
includepath.themes = %kwfPath%/themes
includepath.webApp = app
@@ -103,5 +103,11 @@ body.frontend {
}
}
}
.kwfFormFieldRecaptcha {
label { display: none; }
input {
text-indent: 0px;
}
}
}

0 comments on commit 780969d

Please sign in to comment.