0

Maybe I am missing something, but in symfony examples, in form submission action there's nothing which indicates form data is saved to database. (link). How can I save everything to db?

Example from the link:

public function executeSubmit($request)
{
  $this->forward404Unless($request->isMethod('post'));

  $params = array(
    'name'    => $request->getParameter('name'),
    'email'   => $request->getParameter('email'),
    'message' => $request->getParameter('message'),
  );

  $this->redirect('contact/thankyou?'.http_build_query($params));
}
1
  • You are right. The codes will not save the form data into database. Commented Mar 19, 2010 at 7:43

3 Answers 3

1

If you have a form that's based on a model (eg Doctrine or Propel object), you'll need to do something like the following in your action:

$this->form = new MyForm();

$this->form->bind($params);

if ($this->form->isValid())
{
  $this->form->save();
}

These seem to be the crucial steps that you're missing. As others have pointed out, the Symfony tutorials provide good examples of this.

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look at http://www.symfony-project.org/forms/1_4/en/04-Propel-Integration:

In a Web project, most forms are used to create or modify model objects. These objects are usually serialized in a database thanks to an ORM. Symfony's form system offers an additional layer for interfacing with Propel, symfony's built-in ORM, making the implementation of forms based on these model objects easier.

Comments

0

As well as VolkerK's link, the jobeet tutorial covers doctrine (or propel if you prefer that as your ORM) forms.

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.