quardas
quardas

Reputation: 691

symfony 1.4 forms - how to set value of one field while submiting the form?

how can I do this?

I'm trying:

$this->form->getObject()->setWebsiteid($website);

$this->form->setDefault('websiteid', $website);

$request->setParameter('websiteid', $website);

none from above doesn't work

my code:

$this->form = new sfGuardRegisterForm();

if ($request->isMethod('post'))
{
  $website=new Website();
  $website->save();

  $this->form->bind($request->getParameter($this->form->getName()));
  if ($this->form->isValid())
  {
    /* here I try do that */
    $this->form->getObject()->setWebsiteid($website);
    /* here I try do that end */

    $user = $this->form->save();
    $this->getUser()->signIn($user);

    $this->redirect('@homepage');
  }
}

Upvotes: 1

Views: 3876

Answers (1)

j0k
j0k

Reputation: 22756

Is websiteid part of your User model ?

Do you use the widget of websiteid in your form ?

You can add the value after the save:

$user = $this->form->save();
$user->setWebsiteid($website);
$user->save();

But the first solution seems ok to me..

Upvotes: 1

Related Questions