PHP: 表单中的文本区域回显在验证期间不会回显

PHP: Text Area echo in form won't echo during validation

目前我有一个通过验证的表单,并输入了回显语句并返回了需要填写的错误。我的评论区在标签内。当它为空时会抛出错误。但是当它被填满而其他区域为空时,它不会回显之前输入的文本。

我查看了另一个声称有答案的问题。以前我在我的价值结果中使用:<?php echo $_POST['email']; ?>。 "answer" 表示要用 htmlentities() 替换值:<?php echo htmlentities($comments, ENT_COMPAT,'ISO-8859-1', true);?> 但是,这也不起作用。

我希望在输入文本时回显评论,但其他区域仍需要信息。

HTML 表单文本区域:

<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="Please enter your comments here..." value="<?php echo htmlentities($_POST['comments'], ENT_COMPAT,'ISO-8859-1', true);?>"></textarea>

PHP(不确定此答案中是否需要):

<?php
if(!empty($_POST)){
$POST = filter_post($_POST);
$invoice = array_splice($POST,3,1);
$MSG = check_empty($POST);
if(!array_filter($MSG)){
    $POST['invoice'] = $invoice['invoice'];
    if(send_mail($POST)){
        $MSG[] = "Email Success";
    }
    else{
        $MSG[] = "Email Failed";
    }
}
}
function filter_post($POST){
$keys = array('name','phone','email','invoice','comments');
$POST = array_intersect_key($POST, array_flip($keys));
$POST = array_map('strip_tags', $POST);
return($POST);
}
function check_empty($POST){
foreach($POST as $key => $value){
    if(empty($value)){
        $MSG[] = "You need to fill out the $key section";
    }
}
return($MSG);
}
function send_mail($POST){
extract($POST);
$to = 'jordan@jordandavis.work';
$sbj = 'New Question For Se7en Service!';
$msg = "Name: $name \n Phone: $phone \n Email: $email \n Invoice #: $invoice \n Comments: $comments";
$headers = "From: $email";
return(mail($to, $sbj, $msg, $headers));
}
function output_errors($MSG){
return '<ul><li>' . implode('</li><li>', $MSG) . '</li></ul>';  
}
?>

Link to question with answer that didn't work for me.

你应该使用

 <textarea><?=$your_value?></textarea>

而不是

<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="Please enter your comments here..." value="<?php echo htmlentities($_POST['comments'], ENT_COMPAT,'ISO-8859-1', true);?>"></textarea>

<textarea> 元素没有 value 属性。 'value' 设置在 opening/closing 标签之间 ->

<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="Please enter your comments here...">
    <?php echo htmlentities($_POST['comments'], ENT_COMPAT,'ISO-8859-1', true);?>
</textarea>

http://www.w3.org/TR/html401/interact/forms.html#h-17.7

http://www.w3.org/TR/html-markup/textarea.html