sas
08-06-2003, 01:43 PM
I'm trying to check that all forms have been filled in on a feedback form if they have then it sends a mail and displays a 'well done' page, if they haven't it displays an error page. Thing is all it does is mail me and displays well done whatever i do. I realise it would be a better way to check on a per form basis and echo back to the user which particular box had the problem, but hey i wanted to use an array for the first time.
I think i've used the array wrong, its the first time i've actually tried to do something using an array. Either that or empty() is the wrong function. Anyway does anyone know where i'm going wrong?
<?php
//create short var names
$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];
$toaddress = 'dean@localhost';
$subject = 'Feedback from website';
$mailcontent = 'Customer Name: '.$name."\n"
.'Customer email: '.$email."\n"
."Customer comments: \n".$feedback. "\n";
$fromaddress = 'From: webserver@example.com';
?>
<html>
<head>
<title>Bob's Auto Parts - Feedback</title>
</head>
<body>
<?php
//check form is filled correctly
$empty = array('$name', '$email', '$feedback' );
if(empty($empty))
{
echo '<h1>Feedback not sent</h1>';
echo '<p>You did not fill in all the required forms.</p>';
}
else
{
mail($toaddress, $subject, $mailcontent, $fromaddress);
echo '<h1>Feedback submitted</h1>';
echo '<p>Your feedback has been sent.</p>';
}
?>
</body>
</html>
I think i've used the array wrong, its the first time i've actually tried to do something using an array. Either that or empty() is the wrong function. Anyway does anyone know where i'm going wrong?
<?php
//create short var names
$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];
$toaddress = 'dean@localhost';
$subject = 'Feedback from website';
$mailcontent = 'Customer Name: '.$name."\n"
.'Customer email: '.$email."\n"
."Customer comments: \n".$feedback. "\n";
$fromaddress = 'From: webserver@example.com';
?>
<html>
<head>
<title>Bob's Auto Parts - Feedback</title>
</head>
<body>
<?php
//check form is filled correctly
$empty = array('$name', '$email', '$feedback' );
if(empty($empty))
{
echo '<h1>Feedback not sent</h1>';
echo '<p>You did not fill in all the required forms.</p>';
}
else
{
mail($toaddress, $subject, $mailcontent, $fromaddress);
echo '<h1>Feedback submitted</h1>';
echo '<p>Your feedback has been sent.</p>';
}
?>
</body>
</html>