diff --git a/inc/abstractfield.class.php b/inc/abstractfield.class.php index 11898697d..c0be15971 100644 --- a/inc/abstractfield.class.php +++ b/inc/abstractfield.class.php @@ -66,7 +66,7 @@ public function setFormAnswer(PluginFormcreatorFormAnswer $form_answer): void { $this->parseAnswerValues($this->form_answer->getAnswers()); } else { // Deserialize the default value from DB - $this->deserializeValue($this->fields['default_values']); + $this->deserializeValue($this->question->fields['default_values']); } } diff --git a/inc/form.class.php b/inc/form.class.php index 75afbc8f7..cd207478e 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -981,12 +981,15 @@ public function displayUserForm() : void { if (!isset($_SESSION['formcreator']['data'])) { $_SESSION['formcreator']['data'] = []; } + $formanswer = new PluginFormcreatorFormAnswer(); + $formanswer->loadAnswersFromSession(); TemplateRenderer::getInstance()->display('@formcreator/pages/userform.html.twig', [ 'item' => $this, 'options' => [ 'columns' => PluginFormcreatorSection::COLUMNS, 'domain' => $domain, // For translation 'public' => isset($_SESSION['formcreator_public']), + 'formanswer' => $formanswer, 'use_captcha' => ($this->fields['access_rights'] == PluginFormcreatorForm::ACCESS_PUBLIC && $this->fields['is_captcha_enabled'] != '0'), ] diff --git a/inc/formanswer.class.php b/inc/formanswer.class.php index d6549c2f8..08db3eb68 100644 --- a/inc/formanswer.class.php +++ b/inc/formanswer.class.php @@ -909,6 +909,15 @@ public function loadAnswers(): void { $this->answers = $answers_values; } + /** + * Load answers to questoins from session + * + * @return void + */ + public function loadAnswersFromSession(): void { + $this->answers = $_SESSION['formcreator']['data'] ?? []; + } + public function getAnswers() { return $this->answers; } diff --git a/templates/pages/userform.html.twig b/templates/pages/userform.html.twig index 98f39b535..7bb0f10b9 100644 --- a/templates/pages/userform.html.twig +++ b/templates/pages/userform.html.twig @@ -91,7 +91,7 @@ {% endif %} {% if not options.public or question.getSubField().isPublicFormCompatible() %} {% set sessionData = session('formcreator') %} - {{ question.getRenderedHtml(options.domain, true, sessionData.data)|raw }} + {{ question.getRenderedHtml(options.domain, true, options.formanswer)|raw }} {% endif %} {% set lastQuestion = question %} {% endfor %}