title: Validation problems with multiple checkboxes (HABTM) on CakePHP form
body: <p><strong>Short version</strong></p>
  
  <p>I have some HABTM checkboxes on a form. Validation is working correctly (at least one checkbox needs to be checked for validation to pass) but the CakePHP error message divs aren't being generated as they should be.</p>
  
  <p><strong>Long Version</strong></p>
  
  <p>I have a from which allows users to fill in their name and email address and then choose from a list of brochures (checkboxes) they'd like to receive.</p>
  
  <p>The form looks like this:</p>
  
  <pre><code>&lt;?php
  echo $this-&gt;Form-&gt;create('Request',array('action' =&gt; 'index'));
  echo $this-&gt;Form-&gt;input('id');
  echo $this-&gt;Form-&gt;input('name');
  echo $this-&gt;Form-&gt;input('email');
  echo $this-&gt;Form-&gt;input('Brochure',array(
          'label' =&gt; __('Information Required:',true),
          'type' =&gt; 'select',
          'multiple' =&gt; 'checkbox',
          'options' =&gt; $list,
          'selected' =&gt; $this-&gt;Html-&gt;value('Brochure.Brochure'),
  ));
  echo $this-&gt;Form-&gt;submit('Submit');
  echo $this-&gt;Form-&gt;end();
  ?&gt;
  </code></pre>
  
  <p>In my controller, <code>$list</code> is set as like this:</p>
  
  <pre><code>$this-&gt;Request-&gt;Brochure-&gt;find('list',array('fields'=&gt;array('id','name')));
  </code></pre>
  
  <p>After reading the 2nd answer (posted by user448164) in <a href="https://stackoverflow.com/questions/2044102/habtm-form-validation-in-cakephp">HABTM form validation in CakePHP</a> on Stack Overflow, I set my Request model up like this:</p>
  
  <pre><code>&lt;?php
  
  class Request extends AppModel {
  
  var $name = 'Request';
  
  function beforeValidate() {
      foreach($this-&gt;hasAndBelongsToMany as $k=&gt;$v) {
          if(isset($this-&gt;data[$k][$k]))
          {
              $this-&gt;data[$this-&gt;alias][$k] = $this-&gt;data[$k][$k];
          }
      }
  }
  
  var $validate = array(
      'name' =&gt; array(
          'rule' =&gt; 'notEmpty',
          'message' =&gt; 'Please enter your full name'
      ),
      'email' =&gt; array(
          'rule' =&gt; 'email',
          'message' =&gt; 'Please enter a valid email address'
      ),
      'Brochure' =&gt; array(
          'rule' =&gt; array('multiple', array('min' =&gt; 1)),
          'message' =&gt; 'Please select 1'
      ),
  );
  ?&gt;
  </code></pre>
  
  <p>This actually works 99% well. If none of the checkboxes are checked, validation fails as it should do. However, the only problem is that Cake isn't setting the "error" class on the <code>&lt;div&gt;</code>, nor is it creating the <code>&lt;div class="error-message"&gt;Please select 1&lt;/div&gt;</code> as it should.</p>
  
  <p>For name and email, there is no problem - the error divs are being created properly.</p>
  
  <p>So, to clarify, validation <strong>is</strong> working for my HABTM checkboxes. The only problem is that the error divs aren't being generated.</p>