html - PHP: Text Area echo in form won't echo during validation -
currently have form goes through validation, , echo statement entered , returned errors on needs filled in. commenting area within tag. throws error when it's empty. when it's filled , other areas empty, not echo entered text.
i view question claims have answer. previous using:<?php echo $_post['email']; ?>
in value result. "answer" said replace value , htmlentities() such: <?php echo htmlentities($comments, ent_compat,'iso-8859-1', true);?>
however, did not work either.
i want comments echo, when text entered, other areas still need info.
html form text area:
<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="please enter comments here..." value="<?php echo htmlentities($_post['comments'], ent_compat,'iso-8859-1', true);?>"></textarea>
php (not sure if needed here in 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 $key => $value){ if(empty($value)){ $msg[] = "you need fill out $key section"; } } return($msg); } function send_mail($post){ extract($post); $to = 'jordan@jordandavis.work'; $sbj = 'new question 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>'; } ?>
<textarea>
element not have value
attribute. 'value' set between opening/closing tags ->
<textarea name="comments" maxlength="500" rows="10" cols="10" placeholder="please enter 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
Comments
Post a Comment