Jump to content


Photo

HTML Preset Forms (Newbish)


  • Please log in to reply
5 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 20 September 2006 - 01:23 AM

Hello, I am wondering with a HTML form on some sites they have stuff already in them. Like Name: <please insert name here> and things like that. I was wondering how they do that. Whats the code for it.

- Cheers, Daniel

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 September 2006 - 01:27 AM

Javascript or magic ... for example:

<input type="text" name="name" value=" Your name" size="18" maxlength="100" onFocus="if (this.value==' Your name') this.value=''" onBlur="if (this.value=='') this.value=' Your name'">

Legend has it that reading the manual never killed anyone.
My site

#3 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 20 September 2006 - 03:10 AM

Thanks, but how do i  make it so that if the user just clicks submit with the automatic value of "Your name" in it then it thinks that nothing is in it.

So if i had the code:

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="name" value=" Your name" size="18" maxlength="100" onFocus="if (this.value==' Your name') this.value=''" onBlur="if (this.value=='') this.value=' Your name'">
        <input type="submit" name="submit">
    </form>

<?php	
$name = $_POST['name'];
echo $name;

?>	

Then how would i change it so it wouldnt accept the value "Your Name"?

- Cheers, Daniel

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 September 2006 - 05:46 AM

<?php
if($_POST['name'] == 'Your name' || empty($_POST['name'])
{
	echo "Please enter your name";
}
else {
	// do stuff
}
?>


#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 September 2006 - 12:39 PM

You may want to consider having the default value as a PHP variable as well, not just hard-coded, since the same string will appear in at least 3 places per field.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 24 September 2006 - 04:09 AM

Thanks, Daniel




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users