0

symfony created a dogform class which can edit one dog entry in the database. to display the form in the view i use currently:

<?php echo $form; ?>

well now i want to edit multiple dogs at once (in one page). how do i do this? i think i need the same form multiple times but with different initial data (dogs)

1 Answer 1

1

You need one form, because you can only submit one form at a time, according to html spec. This form will embed a collection of DogForm.

class DogCollectionForm extends sfForm
{
  $dogs = Doctrine::getTable('Dog')->findAll();
  foreach ($dogs as $i => $dog)
  {
    $dogForm = new DogForm($dog);
    $this->embedForm($i, $dogForm);
  }
}

As an enhancement, pass $dogs to form from action as a parameter.

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

3 Comments

ok thank you, display of all rows (in the database) is working, but now i have a problem to save it.
(because sfForm has no own save method). I tried to get the embedded forms (with $this->form->getEmbeddedForms()) in my update action and save each one separately...but i get an error (_csrf_token [Required.])
No, sfForm has a save method, and it saves all embedded forms by default. You must be doing something wrong. Have a look at this example: symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms

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.