Fortuna
Fortuna

Reputation: 19

Adding an empty option-field in a select-field made by the Model

My model User has a belongsTo relationship with Country. So when I add

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

in register.ctp for example, a selectfield of countries is shown.

<select name="foo">
  <option value="germany">Germany</option>
  <option value="finland">Finland</option>
  <option value="usa">USA</option>
</select>

So my question is: Is there a cakeway of getting an empty optionfield as first in the selectfield?

Like:

<select name="foo">
  <option value="0"></option>
  <option value="germany">Germany</option>
  <option value="finland">Finland</option>
  <option value="usa">USA</option>
</select>

Upvotes: 0

Views: 46

Answers (2)

Ronny Vindenes
Ronny Vindenes

Reputation: 2361

$this->Form->input('country',array('empty'=>'No country'));

Upvotes: 1

minaz
minaz

Reputation: 5780

try this...

$this->Form->input('country', array('empty'=>'Select a country'));

Upvotes: 0

Related Questions