Solved

Text after space character cut off in input text field when reloading php script

Posted on 2006-11-13
6
881 Views
Last Modified: 2012-05-05
I have created a genuine PHP-form
that reads bank informations such as account number and
owner of bank account from input text form fields
when the user submits the form. In case there is a mistake
the form is reloaded with calling $_SERVER['PHP_SELF']
and the existing entries in the form's text fields are recreated
by reading from the POST variables. This works fine except in case
where the user puts a text string that is seperated by a
space character. So when he types 'Anne Anyone'
and submits the form, then next time there would only
appear 'Anne' in the input text field. How to return the
complete name combination if it is divided by empty characters ?

0
Comment
Question by:xberry
  • 2
  • 2
  • 2
6 Comments
 
LVL 19

Assisted Solution

by:VoteyDisciple
VoteyDisciple earned 125 total points
ID: 17932279
There's no inherent reason that won't work.  If you echo $_POST['name']  you'll get back exactly what was submitted with the form.

There must be something else going on in the code that's making this happen.  We'd have to see some code to know what.
0
 
LVL 6

Accepted Solution

by:
aescnt earned 125 total points
ID: 17932474
I think I know whats happening, but this is just a guess. This is usually the culprit but there maybe other cases :)
Does your code look like:
<input type=text name=firstname value=<?php echo $_POST['firstname'] ?>>

If so, add quotes around your attribute values:
<input type="text" name="firstname" value="<?php echo $_POST['firstname'] ?>">

Or even better:
<input type="text" name="firstname" value="<?php echo htmlentities($_POST['firstname']) ?>">

Adding htmlentities() in there to make sure that the text is properly escaped.
0
 
LVL 14

Author Comment

by:xberry
ID: 17932736
Actually I solved it some seconds ago, but I am not experienced enough
to tell what was the exact reason behind, so here is what happened:

First, with the described problem, my code looked like this:
<?php someotherphpcode ...; echo 'value='.$_POST["name"];?>

Then I changed it to

<somehtml...  value="<?php echo $_POST["name"];?>">

which returned form-text-values as expected.

It seems to me that echoing the variable together with the html attribute (value)
instead of remaining inline caused the problem here, but why exactly ?

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 19

Assisted Solution

by:VoteyDisciple
VoteyDisciple earned 125 total points
ID: 17932782
Ahh, yep, aescnt solved it.

If you have...   echo 'value='.$_POST['name'];

... it will print out     value=Bob Jones

If you have value="<?php echo $_POST['name']; ?>"

... it will print out     value="Bob Jones"


Why?  Because you wrote quotes in the second one and didn't write quotes in the first one.  It has nothing to do with where or how the code was written, you just forgot quotes in the first version.
0
 
LVL 6

Assisted Solution

by:aescnt
aescnt earned 125 total points
ID: 17932899
If you want it inline:

Change: <?php someotherphpcode ...; echo 'value='.$_POST["name"];?>
To: <?php someotherphpcode ...; echo 'value="'.$_POST["name"].'"';?>
notice the quotes.

And Even better: <?php someotherphpcode ...; echo 'value="'.htmlentities($_POST["name"]).'"';?> -- which is guaranteed not break when the text box contents has quotes and such :)
0
 
LVL 14

Author Comment

by:xberry
ID: 17933544
Ahhh . . . yes and html attributes that are seperate by space chars have
to be inside double qoutation in order to be recognized as the whole expression
that they are . . . right, thanks for that. I have to be rally careful . . . ; ))

I think it should be fair if I give VoteyDisciple the same amount of points
for this, since he helped me/us with the intro for solving this and
it was good to have the stable date from him
>> ("There's no inherent reason that won't work.  
  If you echo $_POST['name']  you'll get back exactly what was submitted with the form.")
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP not parsing ' character 12 46
How do uses indexes to maximize MySQL Searches 14 55
What does != "" mean in programming 8 80
Wordpress Pagination 1 29
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question