If you save the value "none" to your database and in the other cases
0, 1, 2, 3 (id's of the suppliers...) and so on your code should
probably look like this:
$form->input(Modelname.isp_id, array(
'empty' => __('Select your supplier', true)
);
The 'empty' key of the array is used to display the first item on a
select as the defined text, set as a gettext (so you can make it
multilanguage). The Select will be builded up by cake as a select,
because your controller builded it up as a "list", so you do not need
to type $form->select.
other options of the options-array could be:
'type' => select/radio/cechbox,
'label' => set a label for the input,
and so on...
If you follow cake conventions Cake will automatically display a
selected value when editing a record.
With the hint from Melgior your list should be complete in the matter
you wanted it to look like...
On 27 Aug., 20:52, DigitalDude <e.blumsten...@googlemail.com> wrote:
> Hey,
>
> nice one, didn't know about that. Would it be correct for an added
> value at the END of the array to use array_push() ?
>
> On 27 Aug., 20:48, Melgior <melg...@hotmail.com> wrote:
>
> > Hi,
>
> > That's easy. You can use array_unshift to add an entry to the start of
> > an array. Just add this to your controller:
>
> > $isps = $this->Consultation->Isp->find('list');
> > array_unshift($isps, array("none"=>"None of the above"));
>
> > And you should be all set.
>
> > Greets,
>
> > Melgior.
>
> > On 27 aug, 19:52, channel5 <edd.daw...@comptonsolutions.com> wrote:
>
> > > Hi
>
> > > I have a select box that is populated by a database:
>
> > > $isps = $this->Consultation->Isp->find('list');
>
> > > and then output using the form helper in the view:
>
> > > echo $form->select('isp_id', $isps, array('selected' => $ispselect),
> > > array(), 'select your supplier');
>
> > > This works fine, however what I want to do is have an extra option
> > > inserted between the empty element 'select your supplier' and the
> > > first item from the array $isp , this option would allow me to have
> > > the option selected be "none of the below".
>
> > > I can't for the life of me figure out how to do this, can anyone give
> > > me any pointers?
>
> > > Thanks very much
> > > c5
--~--~---------~--~----~------------~-------~--~----~
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