Page 1 of 1

Default value input issue

Posted: Tue Aug 22, 2006 9:54 am
by Moriarty
I have recently started learning php and have come across a problem that I hope you'll be able to help with. I know its probably an easy one but my head is starting to bleed where Ive been hitting it against the wall.

I am trying to design a form with an input box that has a multi-word default value. I can do this with HTML but for some reason the php code seems to only accept the first word and discards the rest.

Code: Select all

<form >
<input type="text" value="This works fine"/>
<input type="text" value=<?php $mytext="This is useless"; echo "$mytext";?> />
</form>
In the example above, the first box has the full value but the second box merely contains the word 'This'.

I looked but couldn't find any explaination for this - but maybe thats just me.

Thanks in advance for any assistance.

Posted: Tue Aug 22, 2006 9:57 am
by feyd
Put quotes around the outside of the PHP code. If you look at the generated HTML you'll see that there are no quotes around the attribute's value.

Posted: Tue Aug 22, 2006 10:00 am
by snowrhythm
Moriarty, simple mistake...try putting your php code in the value attribute within quotes...value="<?php $mytext="this value"; echo $mytext; ?>" . This kind of thing
happens all the time, so don't sweat it :)

Posted: Tue Aug 22, 2006 10:05 am
by Moriarty
Thanks to all. Problem now solved.

Very prompt, concise and informative responses - good here, innit?

Posted: Tue Aug 22, 2006 10:33 am
by Ollie Saunders
yes it is :)