-2

I have a contact form on my site that has four text boxes. It is like a normal contact form, but in the "message" box (which is an html textarea), there are random spaces that show up every time the page loads. The placeholder does not show unless you delete the spaces before typing. What can I do to fix this?

Here is the code:

<div class="form-group">
    <label for="message" class="col-sm-2 col-md-12 col-lg-12 control-label-top color-dark">Message</label>
        <div class="col-sm-10 col-md-6 col-md-offset-3">
            <textarea class="form-control" rows="5" name="message"><?php echo htmlspecialchars($_POST['message']);?>
            </textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
        </div>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Why do you have this: `echo htmlspecialchars($_POST['message'])` on page load ? For the value of the textarea, I mean. – Maximus2012 Nov 10 '16 at 16:46
  • You do realise that on first page load that code will generate undefined index errors. Maybe it is these error messages that are appearing in your `textarea` – RiggsFolly Nov 10 '16 at 16:49
  • the answer lies in the html source; compare it with what you're using now. I've seen this happen too many times – Funk Forty Niner Nov 10 '16 at 17:00

2 Answers2

1

By textareas you must be carefull:

<textarea></textarea

Would not have inner spaces, but:

<textarea> </textarea>

will have them.

0

if the message you loading is from the database, then look at the message column from phpmyadmin. It will be having spaces at the beginning.

  • 1
    that's probably a 10% chance (if not less). The other answer http://stackoverflow.com/a/40533070/1415724 I feel is more the solution here. – Funk Forty Niner Nov 10 '16 at 17:26