Skip to content

Commit

Permalink
Add "captcha_protect_form" event that the recaptcha module grabs and
Browse files Browse the repository at this point in the history
uses to add a captcha to the end of the first group in the form.  If
there are no groups, it adds the captcha at the end of the form.
Updated user_profile and comment forms to use it.
  • Loading branch information
bharat committed Aug 22, 2010
1 parent adc4061 commit dc80cde
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions modules/comment/helpers/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static function get_add_form($item) {
->error_messages("required", t("You must enter a comment"));
$group->hidden("item_id")->value($item->id);
module::event("comment_add_form", $form);
module::event("captcha_protect_form", $form);
$group->submit("")->value(t("Add"))->class("ui-state-default ui-corner-all");

return $form;
Expand Down
1 change: 1 addition & 0 deletions modules/gallery/helpers/user_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static function get_contact_form($user) {
->rules("required")
->error_messages("required", t("You must enter a message"));
module::event("user_profile_contact_form", $form);
module::event("captcha_protect_form", $form);
$group->submit("")->value(t("Send"));
return $form;
}
Expand Down
22 changes: 9 additions & 13 deletions modules/recaptcha/helpers/recaptcha_event.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class recaptcha_event_Core {
static function user_profile_contact_form($form) {
static function captcha_protect_form($form) {
if (module::get_var("recaptcha", "public_key")) {
$form->message->recaptcha("recaptcha")->label("")->id("g-recaptcha");
}
}
foreach ($form->inputs as $input) {
if ($input instanceof Form_Group) {
$input->recaptcha("recaptcha")->label("")->id("g-recaptcha");
return;
}
}

static function comment_add_form($form) {
if (module::get_var("recaptcha", "public_key")) {
$form->add_comment->recaptcha("recaptcha")->label("")->id("g-recaptcha");
}
}

static function register_add_form($form) {
if (module::get_var("recaptcha", "public_key")) {
$form->register_user->recaptcha("recaptcha")->label("")->id("g-recaptcha");
// If we haven't returned yet, then add the captcha at the end of the form
$form->recaptcha("recaptcha")->label("")->id("g-recaptcha");
}
}

Expand Down

0 comments on commit dc80cde

Please sign in to comment.