zendesk / captcha

A captcha plugin for Rails

This URL has Read+Write access

captcha / lib / captcha_helper.rb
100644 24 lines (17 sloc) 0.763 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module CaptchaHelper
    
   def captcha_image(options = {})
      @captcha_image ||= CaptchaUtil::random_image
      image_tag('/system/captcha/' + @captcha_image, options)
   end
   
   def captcha_input_text(label, options = {})
      @captcha_image ||= CaptchaUtil::random_image
      content_tag('label', label, :for => 'captcha') + text_field_tag(:captcha, nil, options)
   end
   
   def captcha_hidden_text
      @captcha_image ||= CaptchaUtil::random_image
      hidden_field_tag(:captcha_validation, @captcha_image.gsub(/\..+$/,''))
   end
   
   def captcha_block(label = 'Please type the characters in the image below')
      content_tag('div', captcha_hidden_text + captcha_input_text(label) + captcha_image, { :class => 'captcha' })
   end
   
end