0

I create a form in Symfony 5:

$form = $this->createFormBuilder()
    ->add('test', TextType::class, [
        'mapped' => false,
        'required' => true
    ])
    ->add('submit', SubmitType::class)
    ->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
    $testForm = $form->getData();
    $session->set('testForm',$testForm);
    return $this->redirectToRoute('other_controller');
}

Now in other controller I want use test value:

$testForm = $session->get('testForm');
dd($testForm['test']->getData());

But not work. How can I use test value?

Error:

Cannot use object of type App\Entity\User as array

5
  • In real I want get username and password frome register user and first redirect to confirm email and then register user
    – user15220416
    Apr 18, 2021 at 14:16
  • @gp_sflover "Cannot use object of type App\Entity\User as array"
    – user15220416
    Apr 18, 2021 at 14:17
  • If it is an object (as it should), and if you have property getters in your User Entity, then why you didn't use $testForm->getUsername();?
    – gp_sflover
    Apr 18, 2021 at 14:33
  • @gp_sflover test is an unmapped and $testForm-.getTest(); not work
    – user15220416
    Apr 18, 2021 at 14:43
  • I edit question
    – user15220416
    Apr 18, 2021 at 15:25

1 Answer 1

0

You can replace this:

$testForm = $form->getData();

whit this:

$testForm = $form['test']->getData();

Your Answer

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