On Mar 12, 7:21 am, avorobiev <[email protected]> wrote:
> Place for adding of additional values to the submitted array is form
> validator for that field, because you need transform it to get valid
> values.

I agree with you but that can be quite cumbersome. I'd say that if
HAUSa needs to get the job done quickly he could best add it in the
updateObject method of the form. This method is always called before
saving a sfDoctrineForm or sfPropelForm.

> Form can be used in some places (frontend + backend), and must work
> equal... That is why adding of additional values in controller action
> isn't good deal.

Couldn't agree more with you, this should never be in the controller.
And using the die statement is a terrible idea. Throw an exception if
the logic doesn't allow for an option so that Symfony can shut down
nicely and inform the user.

> Creating a custom validator extended sfValidatorChoiceMany is the best
> way for my opinion.
>
> On Mar 12, 4:20 am, Lawrence Krubner <[email protected]> wrote:
>
>
>
> > On Mar 10, 12:58 pm, HAUSa
>
> > <[email protected]> wrote:
> > > I got a form, in which users can select multiple values for a field
> > > using sfWidgetFormChoiceMany().
>
> > > Now, is it possible to add more values to the submitted array on
> > > submit? I'm not talking about default values when the form shows, but
> > > specifically when the form gets submitted. So the default values are
> > > added afterwards.
>
> > If I understand you, then easy enough. In your actions.class.php file,
> > just alter your executeUpdate method.
>
> > I needed to add a date that was one day in the future,as a default
> > value, so I did this:
>
> >   public function executeUpdate($request)
> >   {
> >     $this->forward404Unless($request->isMethod('post'));
>
> >     $this->form = new NewNewsForm(NewNewsPeer::retrieveByPk($request-
>
> > >getParameter('id')));
>
> >     $submittedValuesArray = $request->getParameter('new_news');
> >     /*
> >     * 03-09-09 - if I do this:
> >         *     print_r($submittedValuesArray);
> >         *     die(" stopped execution ");
> >         *
> >         * I get an array like this:
> >         *
> >         *     Array ( [title] => Sagisaws beat the Apaches [description] =>
> >         *        A hard fought game, yesterday, down in Del Ray.
> >         *      [active] => 1 [id] => )
> >         *
> >     */
>
> >         if ($submittedValuesArray["id"] == "") $submittedValuesArray["date"]
> > = date("Y-m-d h:m:i", time() + 86400);
>
> >     $this->form->bind($submittedValuesArray);
> >     if ($this->form->isValid())
> >     {
> >       $new_news = $this->form->save();
>
> >       $this->redirect('newnews/edit?id='.$new_news->getId());
> >     }
>
> >     $this->setTemplate('edit');
> >   }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to