I wish to upgrade my ancient Contact Form to a new form as sample of which is positioned at .php here and .html positioned here. It is however presenting a 500 error. What is the error advising of and what might be the resolve so that I can progress with the upgrade? The error log presents the following information on Undefined variables:
PHP Notice: Undefined variable: message_text in C:\wamp\www\PHP Validation\contact.php on line 75
PHP Code:
<span class="message"><?php echo $message_text; ?></span>
PHP Notice: Undefined variable: errors in C:\wamp\www\PHP Validation\contact.php on line 76
PHP Code:
<?php echo $errors; ?>
PHP Notice: Undefined variable: name in C:\wamp\www\PHP Validation\contact.php on line 80
PHP Code:
<input type="text" name="name" class="textfield" value="<?php echo htmlentities($name); ?>" />
PHP Notice: Undefined variable: nameErr in C:\wamp\www\PHP Validation\contact.php on line 81
PHP Code:
</label><br /><span class="errors"><?php echo $nameErr; ?></span></p>
PHP Notice: Undefined variable: email in C:\wamp\www\PHP Validation\contact.php on line 84
PHP Code:
<input type="text" name="email" class="textfield" value="<?php echo htmlentities($email); ?>" />
PHP Notice: Undefined variable: emailErr in C:\wamp\www\PHP Validation\contact.php on line 85
PHP Code:
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>
PHP Notice: Undefined variable: message in C:\wamp\www\PHP Validation\contact.php on line 88
PHP Code:
<textarea name="message" class="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
PHP Notice: Undefined variable: messageErr in C:\wamp\www\PHP Validation\contact.php on line 89
PHP Code:
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>
The complete page contact.php is as follows:
PHP Code:
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
?>
<?php
// we must never forget to start the session
session_start();
?>
<?php
define("EMAIL", "xxxxxxxxx@xxx.xxx");
if(isset($_POST['submit'])) {
include('validate.class.php');
//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($message, "message", 5, 1000);
if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Contact Form Subject";
$email_to = EMAIL;
$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n\n";
$emailMessage .= $message;
//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );
//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");
} else {
//set the number of errors message
$message_text = $v->errorNumMessage();
//store the errors list in a variable
$errors = $v->displayErrors();
//get the individual error messages
$nameErr = $v->getError("name");
$emailErr = $v->getError("email");
$messageErr = $v->getError("message");
}//end error check
}// end isset
?>
<!--Form Handler Ends Here-->
<!--Form Starts Here-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow"/>
<title>Simple PHP Form Demo | Box Model Junkie</title>
<link rel="stylesheet" href="FormStyle.css" type="text/css" media="screen" />
</head>
<!--Form Construction Starts Here-->
<body>
<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $errors; ?>
<?php if(isset($_GET['sent'])): ?><h2>Your message has been sent</h2><?php endif; ?>
<form id="contact_form" method="post" action=".">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $nameErr; ?></span></p>
<p><label>Email: <br />
<input type="text" name="email" class="textfield" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>
<p><label>Message: <br />
<textarea name="message" class="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>
<p><input type="submit" name="submit" class="button" value="Submit" /></p>
</form>
</div>
</body>
</html>
Bookmarks