Skip to content

Commit 9233628

Browse files
committed
fix(form): not well restored save answers after invalid submission
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 4fe46ee commit 9233628

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

inc/form.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,9 @@ public function displayUserForm() {
12991299
echo '</li>';
13001300
}
13011301

1302+
// Delete saved answers if any
1303+
unset($_SESSION['formcreator']['data']);
1304+
13021305
// Show validator selector
13031306
if ($this->fields['validation_required'] != PluginFormcreatorForm_Validator::VALIDATION_NONE) {
13041307
$validators = [];

inc/question.class.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function getDesignHtml() {
171171
$sectionId = $this->fields[PluginFormcreatorSection::getForeignKeyField()];
172172
$fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field';
173173
$field = new $fieldType($this);
174-
174+
175175
$html .= '<div class="grid-stack-item"'
176176
. ' data-itemtype="' . self::class . '"'
177177
. ' data-id="'.$questionId.'"'
@@ -226,10 +226,8 @@ public function getRenderedHtml($canEdit = true, $value = []) {
226226
if (!$field->isPrerequisites()) {
227227
return '';
228228
}
229-
if (isset($_SESSION['formcreator']['data']['formcreator_field_' . $this->getID()])) {
230-
$field->parseAnswerValues($_SESSION['formcreator']['data']['formcreator_field_' . $this->getID()]);
231-
} else if (count($value) > 0) {
232-
$field->parseAnswerValues($value);
229+
if (isset($_SESSION['formcreator']['data'])) {
230+
$field->parseAnswerValues($_SESSION['formcreator']['data']);
233231
} else {
234232
$field->deserializeValue($this->fields['default_values']);
235233
}
@@ -340,7 +338,7 @@ private function checkBeforeSave($input) {
340338

341339
// Might need to merge $this->fields and $input, $input having precedence
342340
// over $this->fields
343-
$input['default_values'] = $this->field->serializeValue();
341+
//$input['default_values'] = $this->field->serializeValue();
344342

345343
return $input;
346344
}
@@ -380,9 +378,6 @@ public function prepareInputForAdd($input) {
380378
} else {
381379
$input['row'] = $maxRow + 1;
382380
}
383-
// if (!isset($input['height'])) {
384-
// $input['height'] = '1';
385-
// }
386381

387382
// generate a unique id
388383
if (!isset($input['uuid'])
@@ -413,7 +408,7 @@ public function prepareInputForUpdate($input) {
413408
return false;
414409
}
415410

416-
// generate a uSnique id
411+
// generate a unique id
417412
if (!isset($input['uuid'])
418413
|| empty($input['uuid'])) {
419414
if (!isset($this->fields['uuid']) && $this->fields['uuid'] != $input['uuid']) {
@@ -467,9 +462,9 @@ protected function serializeDefaultValue($input) {
467462
return $input;
468463
}
469464

470-
/**
465+
/**
471466
* Update size or position of the question
472-
* @param array $input
467+
* @param array $input
473468
* @return boolean false on error
474469
*/
475470
public function change($input) {
@@ -632,7 +627,7 @@ public function post_purgeItem() {
632627
// 'row' => ['>', $row],
633628
// $sectionFk => $this->fields[$sectionFk]
634629
// ]
635-
// );
630+
// );
636631
}
637632

638633
// Always show questions with conditional display on the question being deleted

0 commit comments

Comments
 (0)