E-mail form error message

Associate
Joined
13 Jan 2007
Posts
2,424
Location
Belfast,Northern Ireland
I have this working almost how I want, just need to add in some validation for the text areas. However there is a problem that exists, when you first go to the page you will see a feedback message despite having done nothing...I dont understand why this is happening or how to remove it.

www.warfinder.co.uk

Code:
<div class="small-content-middle">
               <form id="form_message" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
 <input type="text" name="name" value="Enter Name"> <br /><br />
 <textarea rows="6" cols="24"  name="message">Enter Your Message
 </textarea>
<br/><br/><?php
$error_msg = "hello";
$to = "[email protected]";
$name = $_POST['name'];
$subject = "Queen's Radio Message From " . $name;
$txt = $_POST['message'];

if (mail($to,$subject,$txt))
{
	$error_msg = '<font color="#FF0000">*Message Sent</font>';
}
else
{
	$error_msg = '<font color="#FF0000">*Message Failed</font>';
}
echo $error_msg ?><br/>
<input type="submit" value="Submit">
</form>


                   </div>
 
Have I understood this correctly as it is now not working. Im not getting the email and no feedback message ever occurs

Code:
<form id="form_message" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
 <input type="text" name="name" value="Enter Name"> <br /><br />
 <textarea rows="6" cols="24"  name="message">Enter Your Message
 </textarea>
<br/><br/><?php
$error_msg = "";
$to = "[email protected]";
$name = $_POST['name'];
$subject = "Queen's Radio Message From " . $name;
$txt = $_POST['message'];

if ($_SERVER['REQUEST_METHOD'] == 'post')
{
	if (mail($to,$subject,$txt))
	{
	$error_msg = '<font color="#FF0000">*Message Sent</font>';
	echo $error_msg;
	}
	else
	{
	$error_msg = '<font color="#FF0000">*Message Failed</font>';
	
	}
} 
echo $error_msg;
 ?><br/>
<input type="submit" value="Submit">
</form>
 
Sorry really should have caught that myself and did wonder but assumed it had to match the method type.

Still having issues with my attempt at validation. It works correctly in terms of function but I dont want it to send if the user leaves the fields empty. Will use JS to clear the boxes on click soon enough.

Code:
<form id="form_message" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
 <input type="text" name="name" value="Enter Name"> <br /><br />
 <textarea rows="6" cols="24"  name="message">Enter Your Message
 </textarea>
<br/><br/><?php
$error_msg = "";
$to = "[email protected]";
$name = $_POST['name'];
$subject = "Queen's Radio Message From " . $name;
$txt = $_POST['message'];
$valid = false;

if ($name != "" && $name != "Enter Name" && $txt != "" && $txt != "Enter Your Message")
{
	$valid = true;
}
else
{
	$valid = false;
}

if ($valid = true && $_SERVER['REQUEST_METHOD'] == 'POST'){
		if (mail($to,$subject,$txt))
		{
		$error_msg = '<font color="#FF0000">*Message Sent</font>';
		}
		else
		{
		$error_msg = '<font color="#FF0000">*Message Failed</font>';	
		}
	} 
else if ($valid = false && $_SERVER['REQUEST_METHOD'] == 'POST')
{
	$error_msg = '<font color="#FF0000">*Missing Information</font>';
}
echo $valid;
echo $error_msg;
 ?><br/><br/>
<input type="submit" value="Submit">
</form>
 
Thank you fabien, that's finally working as it should, I hate wasting times on things I should be solving in a few minutes. I guess I am less familiar with php than I thought which aint good!

Yeah I know of jquery tools, luckily i've done several sliders before and tabbed windows so im hoping (fingers crossed) it aint too much of a pain in the arse. Problem will be linking it will images from a db but i cant imagine that being much of an issue
 
Back
Top Bottom