3

I have some problem with entering default values in an input text form. For example if the default value is "Hello World", the input field will only show "Hello." It only accepts the first word. Is there something that I can do to accept the whole string?

<input type='text' name='prod_name' size='30' value=<?=$prname?> />
oLraX
  • 217
  • 4
  • 14

4 Answers4

7

You need to put quotes around your value attribute

<input type='text' name='prod_name' size='30' value='<?=$prname?>' />

Notice, a $prname value of "Hello World" would yield this:

<input type='text' name='prod_name' size='30' value=Hello World> />

In which case the HTML thinks your input value is "Hello", and "World" is some non-existent boolean attribute.

tomaroo
  • 2,524
  • 1
  • 19
  • 22
2

use ' or " for value like this

<input type='text' name='prod_name' size='30' value='<?=$prname?>' />
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
1

What Baba just said and I don't know if this would affect it, but you forgot to put the php inside quotes.

value="<?php // code here ?>"
Matt Whitehead
  • 1,743
  • 3
  • 19
  • 34
0

(Although this is an old post and it already has an answer I would like to add a different case just for reference:)

In my case my default value was coming from a query. I needed to set a description (text with spaces) in an input value of type 'text' and I had the same issue and fixed it like this:

<input type="text" name="Description" value="'. $row["Description"].'">
MLBDG
  • 1,357
  • 17
  • 23