Skip to content

Commit

Permalink
fix(form): values handling with twig
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 1, 2022
1 parent da458fa commit ecceb93
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inc/abstractfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

Expand Down
3 changes: 3 additions & 0 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
Expand Down
9 changes: 9 additions & 0 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/userform.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit ecceb93

Please sign in to comment.