title: Codeigniter form validation callbacks not working
body: <p>Probably something simple, but heres my problem, I have implememnted a simple captcha into my user system, but I can't seem to use the callback form validation to check to see if the captcha is correct.</p>
  
  <p>I store the answer in the users session, and on form validation I check if it is correct.</p>
  
  <p>You can see it live here: <code>http://77.96.119.180/beer/user/register</code>
  Please excuse any references to beer ;)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('captcha', 'Image verification', 'trim|required|xss_clean|integer|callback_captcha_check');
  </code></pre>
  
  <p>Here is part of the form</p>
  
  <pre><code>// CAPTCHA
  $random_word = rand(10000, 99999);
  $vals = array(
      'word'   =&gt; $random_word,
      'img_path'   =&gt; './captcha/',
      'img_url'    =&gt; 'http://77.96.119.180/beer/captcha/',
      'font_path'  =&gt; './captcha/fonts/pdark.ttf',
      'img_width'  =&gt; '150',
      'img_height' =&gt; 50,
      'expiration' =&gt; 7200
  );
  
  $cap = create_captcha($vals);
  
  // Store captcha answer in session
  $this-&gt;session-&gt;set_userdata('captcha_answer', $random_word);
  
  $content .= form_label('Please enter the numbers in the box to verify you are human (Hint: Only numbers will appear)', 'captcha');
  $content .= '&lt;div class="left" style="margin-left:20px;"&gt;' . $cap['image'] . '&lt;/div&gt;';
  $content .= form_input(array('name' =&gt; 'captcha', 'value' =&gt; '', 'class' =&gt; 'right', 'style' =&gt; 'width:75%; margin-top:5px;'));
  </code></pre>
  
  <p>And here is the callback function</p>
  
  <pre><code>public function captcha_check($str)
      {
          if ($str == $this-&gt;session-&gt;userdata('captcha_answer'))
          {
              // Captcha is correct
              $this-&gt;form_validation-&gt;set_message('captcha', 'The %s was wrong, please try again');
              return FALSE;
          }
          else
          {
              return TRUE;
          }
      }
  </code></pre>