1

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>';  
}
?>

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

Community
  • 1
  • 1
blackRob4953
  • 1,585
  • 2
  • 12
  • 15
  • 1
    `` – Sean Aug 25 '15 at 05:55
  • Perfect my man. Thank You! Did not know – blackRob4953 Aug 25 '15 at 05:59
  • Sean, make this an answer instead of a comment so I can vote it correctly. – blackRob4953 Aug 25 '15 at 06:00
  • added it as an answer http://stackoverflow.com/a/32196648/689579 – Sean Aug 25 '15 at 06:09
  • THANKS. Wanted to give you the credit – blackRob4953 Aug 25 '15 at 06:10

2 Answers2

1

<textarea> element does not have a value attribute. The 'value' is set between the opening/closing tags ->

<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
or
http://www.w3.org/TR/html-markup/textarea.html

Sean
  • 12,443
  • 3
  • 29
  • 47
0

You should use

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

instead of

<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>
Drop Shadow
  • 845
  • 3
  • 12
  • 28