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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:11:44+00:00 2026-05-24T11:11:44+00:00

I created a Select ELement in a form. $parentId = $this -> createElement(‘select’, ‘parent_id’);

  • 0

I created a Select ELement in a form.

    $parentId = $this -> createElement('select', 'parent_id');
    $parentId -> setLabel("Select a parent menu:")
                -> setRequired(true);
    $parentId->addMultiOption(0, 'None');
    $this->addElement($parentId);

Its option have to loaded as per the value passed from the query String or URL. So, in my controller I fetched the values I required from the url and loaded extra item to the element, using following code

private function renderParentElement($menu_id, $parent = 0) {
    $mapper = $this -> mapper();
    $select = $mapper -> select();
    $select -> where("parent = ?", $parent)
            -> where("menu_id = ?", $menu_id);
    $menus = $mapper -> fetchAll($select);
    if($menus -> count() > 0) {
        foreach($menus as $menu) {
            $this -> form() -> getElement('parent_id') -> addMultiOption($menu -> id, $menu -> label);
        }
    }
}

And the Action method calling the above method is this

public function addAction()
{
    $menu = $this->_request->getParam('menu');

        $mapperMenu = new Application_Model_Mapper_Menu();
        $this -> view -> menu = $mapperMenu -> find($menu);

        if($this -> _request -> isPost() && $this -> form() -> isValid($_POST)) {
            $data = $this -> form() -> getValues();
            $menuItem = $this -> model();
            $menuItem -> setParent($data['parent']);
            $menuItem -> setMenu_id($data['menu_id']);
            $menuItem -> setLabel($data['label']);
            $menuItem -> setLink($data['link']);
            $menuItem -> setPage_id($data['page_id']);
            $this -> mapper() -> save($menuItem);

            $this -> _request -> setParam('menu', $data['menu_id']);
            $this -> _forward('index');
        }
        $this -> form() -> populate(array('menu_id' => $menu));
        $this -> renderParentElement($menu, 0);
        $this->view->form = $this -> form();
}

Now everything thing was working fine. The elements were loaded correctly and displaying correctly as well.
But when I submitted it, the select box gives error as 1 is not found is the haystack, here 1 is the value of the item i selected, which is loaded from the controller.

Please help me solve this error !!!

  • 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-24T11:11:45+00:00Added an answer on May 24, 2026 at 11:11 am

    From what I see you have no values in your element before you call isValid

    $this->renderParentElement($menu, 0);
    // you have to set the options in the form before you validate it
    if($this->_request->isPost() && $this->form()->isValid($_POST)) { ... }
    

    Note that you don’t have to call your render method twice, just move it up to before the if statement

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

Sidebar

Related Questions

My form has a custom element like below, created using custom ajax: <select jwcid=testtest
Using CakePHP, I created select-option form element with: echo $form->select('items', $numeration , array('selected' =>
I want to create a form element that gonna output like this select date:
I have a select list I've created in a form alter, however, when I
Once I created a form builder where user could select any number of fields
Here is my table in the dataset: SELECT tag_work_field.* FROM tag_work_field I created this
I've got a strange problem. I created a custom form element. I created it
I've created a form with one drop down menu to choose from as well
Here is a form element I have. <select id=state name=state style=width: 212px;> <option value=nsw>New
In one of my current projects I have a dropdown (select) form element. I

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.