[solved] Dropdown list options from an array

First of all I know this should really be in a database but for some reason I decided to do it in an array and now I’m stuck with it, so anyway…

I have an array that I use to generate a dropDownList:




public function getReferrers()

{

	return array(

		1=>'Google Search',

		2=>'Word of Mouth',

		3=>'Recommendation',

	);

}


public function getReferrer() // display the referrer on 'view' action

{

	return $this->Referrers[$this->referrer];

}


$form->dropDownList($model, 'referrer', $user->Referrers); ?>



This dropdown appears on the front end form and allows users to select the referrer. The integer key value gets stored in the database.

For now there are only 3 options but I envisage this list will grow longer - there will be around 10-12 options. Anyway in addition to these options there will be 1 custom option "Manual Create". This is to describe where the record has been manually created by the admin. Therefore this custom option should not appear on the front end form, but it does need to appear in the back end search form (so I can search for all "Manual Create" records).

How can this be achieved?

You may change you function in such way:




public function getReferrers($showManual = true)

{

  $items = array(

	1 => 'Google Search',

	2 => 'Word of Mouth',

	3 => 'Recommendation',

  );

  if($showManual)

  {

	$items[4] = 'Manual';

  }

  return $items;

}



In such case in dropdown list you will call it as


$form->dropDownList($model, 'referrer', $user->getReferrers(false));

and the other code will stay unchanged.