How is the event_name stored in the database? As a numeric index or as
a text field?

The code you've written assumes it's a numeric index (value '2' is
displayed as 'Anniversary', ...)

If it's a text field then you need to have the same values as display
fields; the easiest way to do this is:

$event_names = array('Birthday', 'Anniversary', ...);
$event_names = array_combine($event_names, $event_names);

This corresponds to this more long-winded code:

$event_names = array(
  'Birthday' => 'Birthday',
  'Anniversary' => 'Anniversary',
  ...
);

On Jan 18, 10:41 am, krr <[EMAIL PROTECTED]> wrote:
> I have an events table which has event_name as one of the fields. The
> value for this field is restricted (has to be a value from a set of
> values, like 'Birthday', 'Anniversary', etc). So it is better to have
> a dropdown instead of textbox in the views (add & edit).
>
> Since these are not part of any table, I cannot use generateList in
> the controller. So I used the below code in the controller.
>
> $event_names = array('1'=>'Birthday', '2'=>'Anniversary', /*... etc...
> */);
> $this->set(compact('event_names'));
>
> I am using the below code for event_name field in the views.
>
> echo $form->input('event_name');
>
> This works for add and dropdown appears. But in edit, the dropdown
> does not automatically select the proper value according to the value
> of event_name from the database.
>
> Is there something I am missing?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to