Wednesday, April 29, 2009

Re: Maintaining drop down menus when validation fails?

Hi Brian,
Pretty obvious, should have thought of that! -Thanks for the tip!

On Apr 22, 9:35 pm, brian <bally.z...@gmail.com> wrote:
> Just do your find('list') for the select options outside of any if/else block:
>
> public function action()
> {
>         if (!empty($this->data))
>         {
>                 if ($this->Whatever->save($this->data))
>                 {
>                         // redirect
>                 }
>                 else
>                 {
>                         // flash msg, no redirect
>                 }
>         }
>         $this->set(
>                 'foods',
>                 $this->Food->find('list', array(...))
>         );
>
> }
>
> This way, the only time you're not fetching the options is when you've
> redirected after a successful save.
>
>
>
> On Wed, Apr 22, 2009 at 4:52 PM, _Z <Zmcar...@gmail.com> wrote:
>
> > Hello Cake Community!
>
> > I was wondering if there is a standard approach to maintaining drop
> > down menus within a view when the submitted data does not pass
> > validation (in the model.)
>
> > For example, I have a dropdown menu of foods and other fields within a
> > view.
> > When submitted, the data does not pass validation, and an error
> > message is displayed in the view.
>
> > Instead of showing the drop down menu, all that is displayed is the id
> > of the selected food.
>
> > Does anyone have a good way of maintaining this drop down data in an
> > error condition when validating from the model ?
>
> > Thank you!
--~--~---------~--~----~------------~-------~--~----~
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: