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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:51:40+00:00 2026-06-13T20:51:40+00:00

I’m using Zend Framework 2 and I need a Dependent Dropdown. When user select

  • 0

I’m using Zend Framework 2 and I need a Dependent Dropdown. When user select an category (cat_id on my example) the system fills the subcategory (sca_id) with the correct elements.

I could do that by creating an application like this:

My form looks like:

    $this->add(array(
        'name' => 'cat_id',
        'type' => 'Zend\Form\Element\Select',
        'options' => array(
            'label' => 'Categoria',
            'value_options' => array(
                '' => '',
            ),
        ),
    ));
    $this->add(array(
        'name' => 'sca_id',
        'type' => 'Zend\Form\Element\Select',
        'options' => array(
            'label' => 'Sub Categoria',
            'style' => 'display:none;', // Esse campo soh eh exibido qndo uma categoria for escolhida
            'value_options' => array(
                '' => '',
            ),
        ),
    ));

Note that I don’t fill the value_options there, because I choose do that in my controller, where the Service Manager is avaliable:

    $form = new ProdutoForm('frm');
    $form->setAttribute('action', $this->url()->fromRoute('catalogo-admin', array( ... )));
    // Alimenta as comboboxes...
    $form->get('cat_id')->setValueOptions($this->getCategoriaService()->listarCategoriasSelect());

On the change event of cat_id I do an $.ajax to grab the elements from an Action and fill the sca_id.

That works fine!

The problem is on my validation:

    $this->add(array(
        'name' => 'cat_id',
        'require' => true,
        'filters'  => array(
            array('name' => 'Int'),
        ),
    ));
    $this->add(array(
        'name' => 'sca_id',
        'require' => true,
        'filters'  => array(
            array('name' => 'Int'),
        ),
    ));

When I submit my form it keeps saying : The input was not found in the haystack for both dropdowns…

What I’m doing wrong?

Extra questions : There’s a better way to fill my dropdowns?

Ps.: I guess this question Disable notInArray Validator Zend Framework 2 asks something similar than me, but I wanted to detail more my problem.

  • 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-13T20:51:41+00:00Added an answer on June 13, 2026 at 8:51 pm

    Well, I realized that I should populate my select element before validate my form!

    // SaveAction
    $request = $this->getRequest();
    if ($request->isPost())
    {
        $form = new ProdutoForm();
    
        // Alimenta as comboboxes...
        $form->get('cat_id')->setValueOptions($this->getCategoriaService()->listarCategoriasSelect());
        $form->get('sca_id')->setValueOptions($this->getSubCategoriaService()->listarSubCategoriasSelect());
    
        // If the form doesn't define an input filter by default, inject one.
        $form->setInputFilter(new ProdutoFormFilter());
    
        // Get the data.
        $form->setData($request->getPost());
    
        // Validate the form
        if ($form->isValid())
        {
            // Valid!
        }else{
            // Invalid...
        }
    

    That code works nice. My form now validate perfectly!

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
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
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters

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.