title: Validation performed on initial form load
body: <p>I have a registration form that a user can access via invitation. For example, an invited user can go to <code>/users/register/[invite_code]</code> and get a registration form that is partially populated. I'm seeing something I didn't expect:</p>
  
  <p>If the invite code is valid, we return the user structure and set that in <code>$this-&gt;data</code> so that the form is automagically pre-populated. The pre-population works, but when the form loads, the data validation errors are displayed as though I'd submitted the form. I see a lot of "[Field name] cannot be empty" when a value has been pre-populated.</p>
  
  <p>In response to questions, the register action is called to both display and submit the form. The code looks like this:</p>
  
  <pre><code>public function register( $invite = null ) {
    # Handle a submitted registration
    if( !empty( $this-&gt;data ) ) {
      # Do stuff...
  
      if( $this-&gt;User-&gt;save( $this-&gt;data ) ) {
        $this-&gt;Session-&gt;setFlash( 'Welcome. Thanks for registering.', null, null, 'success' );
        $this-&gt;redirect( $this-&gt;Auth-&gt;redirect() );
      }
      else {
        $this-&gt;Session-&gt;setFlash( 'Oh noz. There\'s a problem with your registration.', null, null, 'validation' );
      }
    }
  
    # If an invite is passed, pull the user attached to that invite.
    if( !empty( $invite ) ) {
      # Attempt to pull the user that owns the invite
  
      if( empty( $user ) ) { # Unrecognized invite code
        # Do stuff...
      }
      else { # Invited user found
        if( !empty( $user['User']['password'] ) ) { # Invited user has already registered
          # Do stuff...
        }
        else { # This is the invited user
          $this-&gt;data = $user;
        }
      }
    }
  }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After coming back to this, the problem comes when I assign the user to <code>$this-&gt;data</code>. When I remove that, no validation errors. Unfortunately, no pre-population either. I need the latter, so I need to find a way of setting the data points without triggering the error messages.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>If I dump <code>$this-&gt;User-&gt;invalidFields()</code>, even as early as the first line of <code>UsersController::beforeFilter()</code>, the array is populated with invalids. How is this possible? What could I possibly be doing that early in the request to cause this?</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>I've also noticed that as I enter <code>UsersController::beforeFilter()</code>, the value of <code>$this-&gt;User-&gt;id</code> is already set. I have no idea where or why, but this seems significant. As far as I know, the first step into the actual application code is the relevant controller's <code>beforeFilter</code> method and the user id is set on the way in.</p>