View Single Post
Old 01-27-2013, 03:12 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
How can I have the 'example' of the field and the var so that people don't have to re-enter their information when the form is validated?
I don't understand that sentence.

Rather than using onfocus() and relying of JavaScript - it's annoying anyway to have the value removed each time (suppose I just want to correct the spelling?) - use HTML5 placeholder:

PHP Code:
<input type="text" value="<?php echo $varname?>" name="name" id="name" placeholder="John Smith" />
If you are using the HTML5 doctype then you don't need ' /' at the end either.

It is also advisable to always use the full php opening tag <?php and echo the value.

You'll notice that if you delete the value and click away from the input the placeholder text will show. However, placeholder text should say something useful such as "Name is required" or "Minimum 5 characters" rather than an actual name, as this is mis-leading.

BTW I think name is a very poor name for the name. Use a little imagination; even 'fullname' is better.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 01-27-2013 at 03:16 AM..
AndrewGSW is offline   Reply With Quote