Jump to content

[SOLVED] HTML form is truncating php text


Brickley

Recommended Posts

Hello all,

 

I have an issue with what should be a simple thing - I insert a php "echo" statement to call up a variable (a short string of several words) for the value of in an html form and the value and the result is truncated at the end of the first word.

 

So for example this line:

 

<input type="text" size="15" name="City" value=<?php echo($City) ?> ><br>

 

calls the variable "$City" that contains the string "Santa Monica" - when the form loads, it displays only the first word - in this case, "Santa" and no space.

 

This page has about 15 forms like that and all the variables I am trying to load - text and numbers - that have a space produce the same result.

 

It doesn't matter if the variable comes from code in the page or is read from a database.

 

Any ideas?

 

Thanks in advance

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

haku, run this code:

 

$var = "Foo Bar";
echo <<<html
<input type="text" name="something" value=$var />
html;

 

Think about it, without the talking marks there the first space that is encountered by the browser will be assumed the ending of the value attribute.

 

Viewing the source it'd look like this:

 

<input type="text" name="something" value=Foo Bar />

 

And only 'Foo' will be displayed in the text box.

Link to comment
Share on other sites

Ahh, I get what you are saying. I was thinking of the HTML end - it will still print out. But you were talking about the browser display, where only the first word will display. I think that what the OP was talking about and what you are talking about are the same things here, so OP - listen to Project Fear! The quotes should solve your problem.

Link to comment
Share on other sites

Bingo!

 

Quotes around the PHP code is not something I'd have thought of, but works.

 

I'm not sure I want to know what "OP" stands for.  :)

 

Thanks again!

 

 

----------------------------------------------------------------------

 

Paradox of the day:  I have no choice but to believe in free will.

 

 

 

Link to comment
Share on other sites

Don't worry, it only means "Original Poster". Remember my reason as to why putting quotes around the PHP, apart from it being the proper way to do it.

 

Without the talking marks there the first space that is encountered by the browser will be assumed the ending of the value attribute.

 

Your value had a space in it, so only the first word would be displayed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.