This is the good old "but I don't wanna follow the HTML standard!" problem again.
Look at the line
<input type=hidden name=test value=$test>
And figure out what would be sent to the browser if $test='I love PHP':
<input type=hidden name=test value=I love PHP>
(you can see this when you view the source in the browser).
So what does the browser send back when the form is submitted?
test=I
and "love" and "PHP" end up being treated by the browser as unrecognised attributes for the <input> tag.
Solution: follow the HTML conding standard and write
<input type=\"hidden\" name=\"test\" value=\"$test\">
And to play it safe:
<input type=\"hidden\" name=\"test\" value=\"".htmlspecialchars($test)."\">