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 7068705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:21:24+00:00 2026-05-28T05:21:24+00:00

I have a need for chained select boxes in my zend framework project: Countries->Regions->Provinces->Towns.

  • 0

I have a need for chained select boxes in my zend framework project: Countries->Regions->Provinces->Towns.

I am using zend form and intend to resubmit to reload the contents of the of the chained select boxes when one of them is changed. I have written some code in a PHPunit test to simulate what I will need in my controllers.
I will require to use this regional structure in quite a few different forms on my site and also plan to enhance with AJAX.

I don’t want to be duplicating this code, so where should I store it and how should it be structured so that I can reuse its functionality. I thought perhaps an action helper?

public function testCanGetRegionalStructureFromUser() {
        $user = new \Entities\User;
        $user = $this->em->getRepository('Entities\User')->findOneByEmail('testuser@yahoo.com');

        $town = new \Entities\Town;
        $town = $user->getTowns_id();

        // if user has not town input, then use the default 
        if (is_null($town)) {
            $config = Zend_Registry::get('config');
            $defaulttownid = $config->towns->defaultid;
            $town = $this->em->getRepository('Entities\Town')->find($defaulttownid);
        }

        // get the town id
        $townid = $town->getId();

        //get the province
        $province = $town->getProvinces_id();
        $provinceid = $province->getId();

        //get the region
        $region = $province->getRegions_id();
        $regionid = $region->getId();

        //get the country
        $country = $region->getCountries_id();
        $countryid = $country->getId();

        $countrylist = $this->em->getRepository('Entities\country')->findActiveCountries();
        $regionlist = $this->em->getRepository('Entities\Region')->findActiveRegions($countryid);
        $provincelist = $this->em->getRepository('Entities\Province')->findActiveProvinces($regionid);
        $townlist = $this->em->getRepository('Entities\Town')->findActiveTowns($provinceid);
    }

countrylist,regionlist etc. are ready to be injected into my form as options that will be used to populate the select boxes.

  • 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-05-28T05:21:24+00:00Added an answer on May 28, 2026 at 5:21 am

    I think that for this case, creating a composite Zend_Form_Element makes the most sense.

    This way, you can easily add the element to your forms with only a few lines of code, you can have validators built into the element so you aren’t repeating that logic, and with your own decorator you can easily control the layout of the selections and only have to change one file to reflect the changes to all forms.

    For one of my projects I created a composite element that had a plain text box that used autocomplete to search customers in real time as the user types. Once a customer is selected from the autocomplete list, an ajax call is made that fetches a list of properties owned by that customer and a dropdown box is updated with the new list.

    The element provides access to the data values (customer, property) and the decorator renders the individual elements in a group, and set up the necessary event handlers and ajax calls (most of that code is in an external .js file.

    Creating and Rendering Composite Elements
    Similar to the above reference, by Matthew Weier O’Phinney
    Video: Creating composite elements

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

Sidebar

Related Questions

Currently I have my chained select menus working great. However currently when the page
I am using WIX for my application's setup project, I have to install device
I have this jQuery function for chained drop down boxes: function updateCargoDestinations() { $.ajax({
I have need to produce LINE, BAR, and PIE charts in Rails. I have
I have need to return multiple results from a subquery and have been unable
I have need to pack four signed bytes into 32-bit integral type. this is
I have need for a function pointer that takes two arguments and returns a
I have need for AutoCompliteTextView in PreferenceActivity so I extended DialogPreference. My auto-complite is
In my app I have need to trigger show some custom view when status
I have a need for a model(?) on my app which basically contains a

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.