Currently I have a form that goes through validation, and echo statement that are entered and returned errors on what needs to be filled in. My commenting area is within a tag. It throws the error when it's empty. But when it's filled and other areas are empty, it DOES NOT echo the previously entered text.
I view another question that claims to have an answer. Previous I was using:<?php echo $_POST['email']; ?>
in my value result. The "answer" said to replace value with and htmlentities() as such: <?php echo htmlentities($comments, ENT_COMPAT,'ISO-8859-1', true);?>
However, that did not work either.
I want the comments to echo, when text is entered, but other areas still need info.
HTML form text area:
<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 (not sure if needed here in this answer):
<?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>';
}
?>