Some Form help

Associate
Joined
19 Jul 2006
Posts
1,847
Hi I have this form
<form class="contactform" action="mailertest.php" method="post">

<div>
<input type="text" onfocus="if(this.value=='Name')this.value='';" onblur="if(this.value=='')this.value='Name';" name="name" class="input-textarea" value="Name" id="bname" />

<br />
<br />

<input type="text" onfocus="if(this.value=='Email')this.value='';" onblur="if(this.value=='')this.value='Email';" name="email" class="input-textarea" value="Email" id="bemail" />

<br />
<br />

<textarea name="comment" cols="8" rows="5"></textarea>

<br />

<input name="Submit" type="submit" value="Send Message" class="input-submit"/>
</div>

</form>

Mailertest.php
PHP:
<?PHP 
$to = "[email protected]"; 
$subject = "Messsage from website";
$headers = "Form Mailer";
$forward = 1;
$location = "thankyou.html";

$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 



$msg = "Message sent from website on date  $date, hour: $time.\n\n\n\n"; 

if ($_SERVER['REQUEST_METHOD'] == "POST") {
	foreach ($_POST as $key => $value) { 
		$msg .= ucfirst ($key) ." : ". $value . "\n\n"; 
	}
}
else {
	foreach ($_GET as $key => $value) { 
		$msg .= ucfirst ($key) ." : ". $value . "\n\n"; 
	}
}

mail($to, $subject, $msg); 
if ($forward == 1) { 
    header ("Location:$location"); 
} 
else { 
    echo "Thank you for your message. We will contact you as soon as possible."; 
} 

?>

Now this works. it send the email to me. However there is no validation on there, I dont know how to do this on this form I have tried some javascript but could not get it to work.

At the moment if the person clicks submit without entering i get a email with name
email
( they are there by default) but recently i have got emails with out these which means someone/thing is just running the mailertest.php is there a way of stoping this to

TIA
 
Back
Top Bottom