I've made a form in html/php in which there is a 'textarea' as well. I'm currently implementing error handling; when a mistake has been made in the form, keep the content that has been assigned already by the user.
When a mistake has been made by the user (for example, invalid e-mail address), the message that the user already had typed into the 'textarea', remains there.
However, this is ONLY when a message has been typed in which NO new lines have been used (so by pressing ENTER in the textarea). So in a multiple-line text area, for some reason it doesn't work.
Any ideas on how to fix this?
Part of the code:
if (isset($_GET['textmessage'])) {
$textmessage= $_GET['textmessage'];
echo'<div class="user-details">
<div class="input-box">
<span class="details">Extra message</span>
<textarea style="height: 100px; padding-top: 10px" type="text" name="textmessage" placeholder="message">';
echo $textmessage;
echo '</textarea>
</div>
</div>';}
Part of the action.php:
$textmessage= nl2br(htmlspecialchars($_POST['tekstbericht']));
if (!filter_var($mailFrom, FILTER_VALIDATE_EMAIL)) {
header("Location: form.php?form=invalidemail&name=$name&textmessage=$textmessage");
exit();
}
) isn't interpretable this way in the URL? Is there any way to solve this easily, without having to rewrite the whole post-and-redirect principle? – Jeroen van den Heuvel Jan 26 '22 at 12:45
) isn't interpretable this way in the URL`...well the way to tell that is to check precisely what's being placed in the URL. That way, you don't have to guess. – ADyson Jan 26 '22 at 13:21
strReplace with text just in case those are the hidden dividers for multiple lines. But this didn't anything either. – Jeroen van den Heuvel Jan 26 '22 at 15:08
into a new line for use in a text area](https://stackoverflow.com/questions/6004343/converting-br-into-a-new-line-for-use-in-a-text-area) has plenty of ways to do it. – ADyson Jan 26 '22 at 19:02
` . But both \n and \r needs to be replaced for it to work. `$textmessage_br = str_replace(array("\r","\n"),"QTEXTQ",$tekstmessage)` in the ACTION.php. Then I convert it back with `$textmessage= str_replace("QTEXTQQTEXTQ", ("\n"),$_GET['textmessage']);`. I know it's not ideal, also with the problems you mentioned, but to be short, those will rarely occur on the total website. Again, thanks for all the time and effort you put into this! – Jeroen van den Heuvel Jan 26 '22 at 19:16