I create a form in controller:
$form = $this->createFormBuilder()
->add('test', TextType::class)
->add('submit', SubmitType::class)
->getForm();
and I have this code in my twig page:
{{ form(form, { 'attr': {'autocomplete': 'off'} }) }}
Now when I write a value for input (for example "123456") and when I submit the form and it's invalid, the page refreshes and my input value display "123456" and when I refresh page again value not change.
You have several ways to do it:
value
attribute while rendering the field (could not work on some form themes)Read the symfony documentation on form themes to know which solution is better for your use-case or application.
Anyway, for a validation code input (as read in the comments) I suggest to you to implement a new form type entirely and handle its rendering, options and logic separately.