HTML INPUT

When I post text from HTML <form>  I get no following spaces so if I post text string who sould be 80 bytes long and the text is only 10 bytes i ONLY GET 10 BYTES LONG STRING.  How disable stripping off the spaces ?
soffcecManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
What server is being used - Apache, IIS, nginx?
0
soffcecManagerAuthor Commented:
Windows 2012 IIS
0
Julian HansenCommented:
As far as I know you can't with the default form functionality  - HTML ignores white space. You will need to pad the string on the server.

However, you should be able to do it with jQuery
HTML
  <form action="t2322.php" method="post">
    <input type="text" name="comment" />
    <input type="submit" />
  </form>
  <pre id="result"></pre>

Open in new window

jQuery
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(function() {
  $('form').submit(function(e) {
    e.preventDefault();
    var x = $(this).serialize();
    $.post('t2322.php', x, function(resp) {
      $('#result').html(resp);
    });
  });
});
</script>

Open in new window

Server script (for interest) - this just reflects the input with [ ] around the data to show the spaces.
<?php
echo "[{$_POST['comment']}]";

Open in new window


Working sample here
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Julian HansenCommented:
NB if the jQuery solution does not work for you then I would guess that whatever you are using server side is trimming the input in which case you must pad on the server or terminate the string on the client with a non-whitespace character which you then trim on the server.
0
Dave BaldwinFixer of ProblemsCommented:
Using the simplest possible <form> and text <input>, trailing spaces (in Firefox and Chrome) are sent as '+' signs and are normally converted back to spaces by the server.
1
Julian HansenCommented:
Updated sample following Dave's comment
<form action="t2322.php" method="post">
<input type="text" name="comment" />
<input type="submit">
</form>

Open in new window

Server
<pre><?php
$raw = file_get_contents("php://input");
echo "Raw : [{$raw}]<br/>";
echo "POST: [{$_POST['comment']}]<br/>";
?></pre>

Open in new window

Result
Raw : [comment=abc++++++++++]
POST: [abc          ]

Open in new window

Sample here

I did an initial test to see if I could replicate the authors situation. When I looked at the results it appeared that I had - however, here was my mistake which I think is relevant to this discussion.

I viewed the results as HTML - which means even though the spaces where being sent to the server and reflected back to the browser - the HTML rendering of those results is what "removed" the white space from the submitted value - so the 10 spaces I added to the end of my input came out as a single space when rendered in HTML - an assumption on my part that what I was seeing was a trimmed response was in fact my just not seeing the single space at the end of the output.

This could have been prevented had I used <pre> tags as above to contain the output.

This might be what the author is seeing - the reflected value has the spaces but they are not being shown because of HTML rendering removing the superfluous white space.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.