3

This is how the hidden value is added in the $formBuilder :

->add('depth', 'hidden', array('mapped'=>false, 'data' => 1))

I have a function that is fired ON_PRE_SUBMIT, at the line below I assumed this field's value would change but that is not the case.

$form->get('depth')->setData($depth++); //$depth = $form->get('depth')->getData();

I have also tried to do as shown here :

$data = $event->getData();
$data['depth'] = $depth++;
$form->setData($data);

But nothing changes. I have tried the above codes on other fields and they change the fields values normally. Am I missing something?

Community
  • 1
  • 1
stevenll
  • 1,025
  • 12
  • 29

2 Answers2

4

Set the data on the $event:

$data = $event->getData();
$data['depth'] = $depth + 1;
$event->setData($data);
Nikola K.
  • 431
  • 3
  • 10
1

One thing i noticed is that you are using $depth++ which will assign the value first and then increment it so u will end up assigning the old value. try to change this:

$form->get('depth')->setData(++$depth);

Can you also try to change the Event to POST_SUBMIT, I believe if you use PRE_SUBMIT the submitted data will override any data you modify on PRE_SUBMIT

trrrrrrm
  • 11,362
  • 25
  • 85
  • 130