$data = array( 'name' => 'John', 'email' => 'john@example.com' ); $form = $this->createFormBuilder() ->add('name', TextType::class) ->add('email', EmailType::class) ->getForm(); $form->setData($data);
$user = new User(); $user->setName('John'); $user->setEmail('john@example.com'); $form = $this->createFormBuilder() ->add('name', TextType::class) ->add('email', EmailType::class) ->getForm(); $form->setData($user);In both examples, the setData method is used to set the initial data of the form. The first example sets an array as the data, whereas the second example sets a custom object. The package library used in these examples is the Symfony Form component, which provides form building and processing functionality for PHP applications.