On Mar 9, 12:00 pm, CyrilQ <[email protected]> wrote:
> Hello, i was surprised when reading that setDefault does not exist in
> symfony 1.1.
> I downloaded it and you are right, there is no setDefault on
> sfWidgetSchema class, but i found one in sfForm :
>
>   /**
>    * Sets a default value for a form field.
>    *
>    * @param string $name    The field name
>    * @param mixed  $default The default value
>    */
>   public function setDefault($name, $default)
>   {
>     $this->defaults[$name] = $default;
>
>     $this->resetFormFields();
>   }
>
> So maybe you should try using $this -> setDefault() in your form class
> wich extends sfForm ?


That's interesting. I'll give that a try.

For now, I set a default value in the action, as you can see below. I
needed a date set one day in the future (ial) so I set it up like
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] =>
        *     )
        *
        * This is not the correct way to do this, but I'm going to add the
date here.
        * If id is not set, in other words, if we are just creating the entry
for the
        * first time, then we add a date.
    */
    if ($submittedValuesArray["id"] == "") $submittedValuesArray
["date"] = date("Y-m-d h:m:i")  + 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');
  }












> On Mar 7, 3:26 am, LawrenceKrubner<[email protected]> wrote:
>
> > > > I'm using Symfony 1.1.7
--~--~---------~--~----~------------~-------~--~----~
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