Thursday, August 27, 2009

Re: Joining two arrays to use in a Select box with the formhelper

Yes, you could use array_push() indeed, although you don't even need
to. The PHP manual recommends this method if you want to add just one
entry:

$isps['none'] = "None of the above";

This way 'none' will show up as last in the dropdown, as long as you
put the line after ->find().

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: