title: CakePHP update multiple form fields from selectbox change
body: <p>I'm using CakePHP 2.2. I'm adapting a method of dynamically updating a selectbox which I got from: <a href="http://www.willis-owen.co.uk/2011/11/dynamic-select-box-with-cakephp-2-0/#comment-10773" rel="nofollow">http://www.willis-owen.co.uk/2011/11/dynamic-select-box-with-cakephp-2-0/#comment-10773</a> which works without issue.  It updates the 'hotels' selectbox contents when the users selects a 'region' from another select box.</p>
  
  <p>On the same form, I want to automatically populate multiple 'team' fields with address details from the 'hotels' model when a user selects a 'hotel' from the selectbox.  </p>
  
  <p>The user can then modify the address ... all of this before the user clicks submit on the 'team' add view.</p>
  
  <p>In Team\add.ctp view I have the following code:</p>
  
  <pre><code>    echo "&lt;div id='address'&gt;";
      echo $this-&gt;Form-&gt;input('address_1');
      echo $this-&gt;Form-&gt;input('address_2');
      echo $this-&gt;Form-&gt;input('address_3');
      echo $this-&gt;Form-&gt;input('city');
      echo $this-&gt;Form-&gt;input('postcode');
      echo $this-&gt;Form-&gt;input('country');
      echo "&lt;/div&gt;";
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    $this-&gt;Js-&gt;get('#TeamHotelId')-&gt;event('change',
          $this-&gt;Js-&gt;request(array(
              'controller'=&gt;'hotels',
              'action'=&gt;'getAddress'
              ), array(
              'update'=&gt; '#address',
              'async' =&gt; true,
              'method' =&gt; 'post',
              'dataExpression' =&gt; true,
              'data'=&gt; $this-&gt;Js-&gt;serializeForm(array(
                  'isForm' =&gt; true,
                  'inline' =&gt; true))
                          )
          )
      );
  </code></pre>
  
  <p>In my HotelsController.php I have:</p>
  
  <pre><code>public function getAddress() {
      $hotel_id = $this-&gt;request-&gt;data['Team']['hotel_id'];
      CakeLog::write('debug', print_r($hotel_id, true));
      $address = $this-&gt;Hotel-&gt;find('first', array(
              'recursive' =&gt; -1,
              'fields' =&gt; array('hotel.address_1', 'hotel.address_2', 'hotel.address_3', 'hotel.city', 'hotel.postcode', 'hotel.country'),
              'conditions' =&gt; array('Hotel.id' =&gt; $hotel_id)
              ));
      CakeLog::write('debug', print_r($address, true));
      $this-&gt;set('hotels', $address);
      $this-&gt;set(compact('address'));
      $this-&gt;layout = 'ajax';
  }   
  </code></pre>
  
  <p>hotels\get_address.ctp:</p>
  
  <pre><code>    &lt;?php 
          echo $this-&gt;Form-&gt;input('Team.address_1', array('value'=&gt; $address['Hotel']['address_1']));
          echo $this-&gt;Form-&gt;input('Team.address_2', array('value'=&gt; $address['Hotel']['address_2']));
          echo $this-&gt;Form-&gt;input('Team.address_3', array('value'=&gt; $address['Hotel']['address_3']));
          echo $this-&gt;Form-&gt;input('Team.city', array('value'=&gt; $address['Hotel']['city']));
          echo $this-&gt;Form-&gt;input('Team.postcode', array('value'=&gt; $address['Hotel']['postcode']));
          echo $this-&gt;Form-&gt;input('Team.country', array('value'=&gt; $address['Hotel']['country'])); ?&gt;
  </code></pre>
  
  <p>This now works and the code has been updated.</p>