<?php echo $form->select('Candidate.country_id', array('options' =>
$countries), null, null, true); ?>
should be like this:
<?php echo $form->input('Candidate.country_id', array('empty' => '--
Select Country--')); ?>
You can also ommit the model name, but it will be lees explanatory.
In case you wonder, the input method will know wich type of input to
generate (in this case: a select field), since the $this->viewVars
variable contains the data in appropriate format :) (You can use debug
($this->viewVars); to see what's in store...)
On Mar 28, 3:56 pm, Sourav <souravbas...@gmail.com> wrote:
> 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:
Post a Comment