I am processing a HTML form with PHP. In case of an error (eg. too short string), I write back the string to the html input, to the value attribute. What is the recommended way?
The form input is:
<input type="text" name="firstname">
The PHP script is:
$variable_firstname = filter_input (INPUT_POST, 'firstname', FILTER_UNSAFE_RAW);
if ( mb_strlen($variable_firstname , 'UTF-8') < 3 )
{
print '<input type="text" name="firstname" value="'.$variable_firstname.'">';
}
Should I transform the string eg. with htmlspecialchars() before print?
Thanks!