Skip to content

Commit

Permalink
fix(form): not well restored save answers after invalid submission
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jan 28, 2020
1 parent 4fe46ee commit 9233628
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
3 changes: 3 additions & 0 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,9 @@ public function displayUserForm() {
echo '</li>';
}

// Delete saved answers if any
unset($_SESSION['formcreator']['data']);

// Show validator selector
if ($this->fields['validation_required'] != PluginFormcreatorForm_Validator::VALIDATION_NONE) {
$validators = [];
Expand Down
21 changes: 8 additions & 13 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function getDesignHtml() {
$sectionId = $this->fields[PluginFormcreatorSection::getForeignKeyField()];
$fieldType = 'PluginFormcreator' . ucfirst($this->fields['fieldtype']) . 'Field';
$field = new $fieldType($this);

$html .= '<div class="grid-stack-item"'
. ' data-itemtype="' . self::class . '"'
. ' data-id="'.$questionId.'"'
Expand Down Expand Up @@ -226,10 +226,8 @@ public function getRenderedHtml($canEdit = true, $value = []) {
if (!$field->isPrerequisites()) {
return '';
}
if (isset($_SESSION['formcreator']['data']['formcreator_field_' . $this->getID()])) {
$field->parseAnswerValues($_SESSION['formcreator']['data']['formcreator_field_' . $this->getID()]);
} else if (count($value) > 0) {
$field->parseAnswerValues($value);
if (isset($_SESSION['formcreator']['data'])) {
$field->parseAnswerValues($_SESSION['formcreator']['data']);
} else {
$field->deserializeValue($this->fields['default_values']);
}
Expand Down Expand Up @@ -340,7 +338,7 @@ private function checkBeforeSave($input) {

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

return $input;
}
Expand Down Expand Up @@ -380,9 +378,6 @@ public function prepareInputForAdd($input) {
} else {
$input['row'] = $maxRow + 1;
}
// if (!isset($input['height'])) {
// $input['height'] = '1';
// }

// generate a unique id
if (!isset($input['uuid'])
Expand Down Expand Up @@ -413,7 +408,7 @@ public function prepareInputForUpdate($input) {
return false;
}

// generate a uSnique id
// generate a unique id
if (!isset($input['uuid'])
|| empty($input['uuid'])) {
if (!isset($this->fields['uuid']) && $this->fields['uuid'] != $input['uuid']) {
Expand Down Expand Up @@ -467,9 +462,9 @@ protected function serializeDefaultValue($input) {
return $input;
}

/**
/**
* Update size or position of the question
* @param array $input
* @param array $input
* @return boolean false on error
*/
public function change($input) {
Expand Down Expand Up @@ -632,7 +627,7 @@ public function post_purgeItem() {
// 'row' => ['>', $row],
// $sectionFk => $this->fields[$sectionFk]
// ]
// );
// );
}

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

0 comments on commit 9233628

Please sign in to comment.