You need to surround the attribute value with quotes, and make sure you encode any quotes within the value itself.
Currently, you are generating HTML that looks like:
<input ... value=This is a test>
which gets interpreted as:
<input ... value="This" is="" a="" test="">
You need to generate HTML that looks more like:
<input ... value="This is a test">