Saturday, March 28, 2009

Dynamic Dropdown Population

I have 2 models: Candidate & Country. I am using the following code to
extract data from the countries table & passing it to a dropdown on a
view of the CandidatesController.

class CandidatesController extends AppController {
var $name = 'Candidates';
var $uses = array('Candidate', 'Country');

function resume() {
$countries = $this->Country->find('list', array('fields' => array
('Country.countryname')));
$this->set(compact('countries'));
...
}

----------------------------------------------------------------------------------------------------------------------------------
View (resume.ctp) :
<?php echo $form->select('Candidate.country_id', array('options' =>
$countries), null, null, true); ?>
--------------------------------------------------------------------------------------------------------------------------------

It is showing the output as :

<select name="data[Candidate][country_id]" id="CandidateCountryId">
<option value=""></option>
<optgroup label="options">
<option value="1">Afghanistan</option>
<option value="2">Albania</option>
......
<option value="239">Zimbabwe</option>
</optgroup>
</select>

I don't want to have the <optgroup label="options"> within the list.
Is there a way to eliminate this ? Also I want the empty select option
to have the text "--Select Country--"
i.e <option value="">--Select Country--</option>. How do I accomplish
this?

- Thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: