0

I am trying to create a drop down menu (option) and to fill this drop down i have sent an array list to the view:

            $country = $this->country_list;

            $this->set(compact('country'));

Now my question is does cake have a buildin method for me to set an input field using ($this->Form->input()) with the data of the array list?

1

2 Answers 2

1

take this example

$sizes = array(
        's' => 'Small',
        'm' => 'Medium',
        'l' => 'Large'
);

echo $this->Form->input('size', array('options' => $sizes, 'default' => 'm'));
Sign up to request clarification or add additional context in comments.

Comments

1

In the controller, set the value

$this->set('countries', $this->Country->find('list', array('fields' => 'Country.name')));

To show the dropdown box in the view

$this->Form->input('country_id');

3 Comments

this works only if he has a Country model and a country_id field but he didn't mention about it. Also: $this->Country->find(...) works only in CountriesController but I don't think this is the case
Worked with what was provided, he can adjust it to work within his project.
@BrianKerr Thanks for your response however the country list is not in a database and is just a plain array list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.