From 38c55182b8835754d648e4bace2b4b91e353f45e Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Fri, 15 Apr 2016 13:46:18 +0200
Subject: [PATCH] form prefill: honor empty values

when a form was submitted with an empty input, that data should still
overwrite the preset value.
---
 _test/tests/inc/form/inputelement.test.php | 16 ++++++++++++++++
 inc/Form/InputElement.php                  |  4 +---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/_test/tests/inc/form/inputelement.test.php b/_test/tests/inc/form/inputelement.test.php
index 3257d2a89..38e4e832c 100644
--- a/_test/tests/inc/form/inputelement.test.php
+++ b/_test/tests/inc/form/inputelement.test.php
@@ -39,6 +39,22 @@ class form_inputelement_test extends DokuWikiTest {
         $this->assertEquals('a new text', $input->val());
     }
 
+    function test_prefill_empty() {
+        global $INPUT;
+        $INPUT->post->set('foo', '');
+
+        $form = new Form\Form();
+        $form->addTextInput('foo', 'label text')->val('this is text');
+
+        $html = $form->toHTML();
+        $pq = phpQuery::newDocumentXHTML($html);
+
+        $input = $pq->find('input[name=foo]');
+        $this->assertTrue($input->length == 1);
+        $this->assertEquals('', $input->val());
+    }
+
+
     function test_password() {
         $form = new Form\Form();
         $form->addPasswordInput('foo', 'label text')->val('this is text');
diff --git a/inc/Form/InputElement.php b/inc/Form/InputElement.php
index 694dd0848..0242b6179 100644
--- a/inc/Form/InputElement.php
+++ b/inc/Form/InputElement.php
@@ -128,9 +128,7 @@ class InputElement extends Element {
                 $value = '';
             }
         }
-        if($value !== '') {
-            $this->val($value);
-        }
+        $this->val($value);
     }
 
     /**
-- 
GitLab