Jump to content

Onfocus on a contact form


AndrewC14

Recommended Posts

Hi guys I'll repeat as always...I'm a noob at both PHP and Javascript!

 

I'm having trouble with my errors on my contact form - When a user clicks on the box I would like the text "Please enter your name" to disappear (Which I've done successfully using onfocus) But if they don't click on that box and hit send again the text "Please enter your name does not disappear".

 

It's just to bulletproof my form really and make it more user friendly.

 

Here's my code for it:

 

if(isset($_POST['submit1'])) {

if(isset($_POST['cf_name']))

 

$names = check_input($_POST['cf_name']);

 

if($names=="")

$errorthing="Please enter your name";

 

Then on form (onfocus):

 

onfocus="if (this.value=='<?php echo $errorthing;?>') this.value=''; if (this.value=='<?php echo $names;?>')this.value='<?php $names ?>';"

 

Here's my web link too: http://xzen.co.uk/services/conceptual-model/

 

Thanks in advance, I really appreciate all the help! :)

 

Link to comment
https://forums.phpfreaks.com/topic/261798-onfocus-on-a-contact-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.