Default value input issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Moriarty
Forum Newbie
Posts: 8
Joined: Tue Aug 22, 2006 9:33 am
Location: London, England. Home of Dangermouse.

Default value input issue

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post 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 :)
Moriarty
Forum Newbie
Posts: 8
Joined: Tue Aug 22, 2006 9:33 am
Location: London, England. Home of Dangermouse.

Post by Moriarty »

Thanks to all. Problem now solved.

Very prompt, concise and informative responses - good here, innit?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

yes it is :)
Post Reply