Skip to content

Commit ecceb93

Browse files
committed
fix(form): values handling with twig
1 parent da458fa commit ecceb93

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

inc/abstractfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function setFormAnswer(PluginFormcreatorFormAnswer $form_answer): void {
6666
$this->parseAnswerValues($this->form_answer->getAnswers());
6767
} else {
6868
// Deserialize the default value from DB
69-
$this->deserializeValue($this->fields['default_values']);
69+
$this->deserializeValue($this->question->fields['default_values']);
7070
}
7171
}
7272

inc/form.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,15 @@ public function displayUserForm() : void {
981981
if (!isset($_SESSION['formcreator']['data'])) {
982982
$_SESSION['formcreator']['data'] = [];
983983
}
984+
$formanswer = new PluginFormcreatorFormAnswer();
985+
$formanswer->loadAnswersFromSession();
984986
TemplateRenderer::getInstance()->display('@formcreator/pages/userform.html.twig', [
985987
'item' => $this,
986988
'options' => [
987989
'columns' => PluginFormcreatorSection::COLUMNS,
988990
'domain' => $domain, // For translation
989991
'public' => isset($_SESSION['formcreator_public']),
992+
'formanswer' => $formanswer,
990993
'use_captcha' => ($this->fields['access_rights'] == PluginFormcreatorForm::ACCESS_PUBLIC
991994
&& $this->fields['is_captcha_enabled'] != '0'),
992995
]

inc/formanswer.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,15 @@ public function loadAnswers(): void {
909909
$this->answers = $answers_values;
910910
}
911911

912+
/**
913+
* Load answers to questoins from session
914+
*
915+
* @return void
916+
*/
917+
public function loadAnswersFromSession(): void {
918+
$this->answers = $_SESSION['formcreator']['data'] ?? [];
919+
}
920+
912921
public function getAnswers() {
913922
return $this->answers;
914923
}

templates/pages/userform.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
{% endif %}
9292
{% if not options.public or question.getSubField().isPublicFormCompatible() %}
9393
{% set sessionData = session('formcreator') %}
94-
{{ question.getRenderedHtml(options.domain, true, sessionData.data)|raw }}
94+
{{ question.getRenderedHtml(options.domain, true, options.formanswer)|raw }}
9595
{% endif %}
9696
{% set lastQuestion = question %}
9797
{% endfor %}

0 commit comments

Comments
 (0)