Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:12:49+00:00 2026-06-17T18:12:49+00:00

I’m using CakePHP 2.2. I’m adapting a method of dynamically updating a selectbox which

  • 0

I’m using CakePHP 2.2. I’m adapting a method of dynamically updating a selectbox which I got from: http://www.willis-owen.co.uk/2011/11/dynamic-select-box-with-cakephp-2-0/#comment-10773 which works without issue. It updates the ‘hotels’ selectbox contents when the users selects a ‘region’ from another select box.

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.

The user can then modify the address … all of this before the user clicks submit on the ‘team’ add view.

In Team\add.ctp view I have the following code:

    echo "<div id='address'>";
    echo $this->Form->input('address_1');
    echo $this->Form->input('address_2');
    echo $this->Form->input('address_3');
    echo $this->Form->input('city');
    echo $this->Form->input('postcode');
    echo $this->Form->input('country');
    echo "</div>";

…

    $this->Js->get('#TeamHotelId')->event('change',
        $this->Js->request(array(
            'controller'=>'hotels',
            'action'=>'getAddress'
            ), array(
            'update'=> '#address',
            'async' => true,
            'method' => 'post',
            'dataExpression' => true,
            'data'=> $this->Js->serializeForm(array(
                'isForm' => true,
                'inline' => true))
                        )
        )
    );

In my HotelsController.php I have:

public function getAddress() {
    $hotel_id = $this->request->data['Team']['hotel_id'];
    CakeLog::write('debug', print_r($hotel_id, true));
    $address = $this->Hotel->find('first', array(
            'recursive' => -1,
            'fields' => array('hotel.address_1', 'hotel.address_2', 'hotel.address_3', 'hotel.city', 'hotel.postcode', 'hotel.country'),
            'conditions' => array('Hotel.id' => $hotel_id)
            ));
    CakeLog::write('debug', print_r($address, true));
    $this->set('hotels', $address);
    $this->set(compact('address'));
    $this->layout = 'ajax';
}   

hotels\get_address.ctp:

    <?php 
        echo $this->Form->input('Team.address_1', array('value'=> $address['Hotel']['address_1']));
        echo $this->Form->input('Team.address_2', array('value'=> $address['Hotel']['address_2']));
        echo $this->Form->input('Team.address_3', array('value'=> $address['Hotel']['address_3']));
        echo $this->Form->input('Team.city', array('value'=> $address['Hotel']['city']));
        echo $this->Form->input('Team.postcode', array('value'=> $address['Hotel']['postcode']));
        echo $this->Form->input('Team.country', array('value'=> $address['Hotel']['country'])); ?>

This now works and the code has been updated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:12:50+00:00Added an answer on June 17, 2026 at 6:12 pm

    You can not do in that way as you are trying to accomplish. However, there is a way in which you can update as you want by passing an id from dropdown using ajax and populating all the other fields on the basis of that id. Please make sure in 'update'=>#id you should put the div id of a div containing all the fields you want to show on the page where you want your contents to appear on ajax request.

    Note: Please follow the Richard link which you have given i.e. http://www.willis-owen.co.uk, it will definitely help you that you are trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a text area in my form which accepts all possible characters from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am using jsonparser to parse data and images obtained from json response. When
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.