Solved

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

Posted on 2006-11-13
6
971 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

717 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