I am working on my website and am wanting to create a contact page and a registration page. Performing that task is not a problem. However, I want to have one PHP script to process both of these forms' data and started working on it tonight, handling the contact form.
My problem is that I can not see what I am missing, yet not even the first echo statements go to the browser window. My code follows, can anyone tell me what I have missed? I know that the `header()' calls will not work, since I have `echo'ed out lines of text, but I only have those there for debugging purposes. As I said, the first `echo' statement doesn't even process. I am positive that I am just overlooking something simple, but am unable to determine what that may be. As far as I can tell, all of my brackets, braces and parentheses line up and all of my lines are terminated with a semicolon. I am absolutely stumped at this point. Any and all help is welcome and appreciated!
Cheers,
PekinSOFT
Code: Select all
<?php
/*
* This processes both the "Contact Us" and "Registration" forms.
*
* Contact Us: For this form, this script generates an email to PekinSOFT
* Systems, sends it and displays a thank-you page.
*
* Registration: For this form, this script generates an email to the site
* visitor, detailing their account information and stores their
* account information in the database.
******************************************************************************
* Since this handles two different forms, we will have to pay attention to
* which POST variables are set, so that we can take the appropriate actions
* and not send someone just trying to contact us a signed up email.
*/
echo $_POST['formName'] . "<br />\n";
echo "contact<br />\n";
$contactForm = false;
if ( strcmp($_POST['formName'], "contact") == 0 ) {
echo "($_POST['formName'], contact) are the same<br />\n";
$contactForm = true;
}
// The first thing that we need to determine is which form submitted the data.
if ( $contactForm ) {
echo "Processing the "Contact Us" form…<br />\n";
// Process the message the site visitor wishes to send and thank them
//+ for their input. Explain that, if the message requires a reply,
//+ it could take up to 72 hours for us to do so.
echo "Creating variables…<br />\n";
// Create some variables to use for creating the email message.
$headers = "From: ";
$to = "PekinSOFT@gmail.com";
$subject;
$body;
$signature;
// Check to be sure the variables were set. If they were, store them
//+ to our internal variables from the POST array. If they weren't,
//+ set our error flag and error message, then redirect them back to
//+ the form.
$data_err = false; // Default to a successful transmission.
$data_msg = "<ul>"; // Default to no error message.
echo "Getting submitted data…<br />\n";
// Get the POST variables.
if ( isset ($_POST['email']) ) {
echo "Adding $_POST['email'] to \$headers.<br />\n";
$headers .= $_POST['email'];
} else {
echo "\$_POST['email'] was not set.<br />\n";
$data_err = true;
$data_msg .= "<li><strong>Email</strong> is a required field.</li>";
}
if ( isset ($_POST['name']) and !strcmp($_POST['name'], "First Last") ) {
echo "Setting the signature.<br />\n";
$signature = $_POST['name'];
} else {
echo "Signature was not set.<br />\n";
$data_err = true;
$data_msg .= "<li><strong>Name</strong> is a required field.</li>";
}
if ( isset ($_POST['body']) ) {
echo "Setting the body of the message.<br />\n";
$body = $_POST['body'];
} else {
echo "Body was not set.<br />\n";
$data_err = true;
$data_msg .= "<li><strong>Message</strong> is a required field.</li>";
}
if ( isset ($_POST['subject']) and $_POST['subject'] != "0") {
echo "Determining the subject of the message.<br />\n";
if ( $_POST['subject'] == "1" ) {
echo "\tSubject: Website.<br />\n";
$subject = "Website";
} else if ( $_POST['subject'] == "2" ) {
echo "\tSubject: Services.<br />\n";
$subject = "Services";
} else if ( $_POST['subject'] == "3" ) {
echo "\tSubject: Contracts.<br />\n";
$subject = "Contracts";
} else if ( $_POST['subject'] == "4" ) {
echo "\tSubject: Something else.<br />\n";
$subject = "Something Else";
}
} else {
echo "\tSubject: Not Set.<br />\n";
$data_err = true;
$data_msg .= "<li><strong>Subject</strong> is a required field.</li>";
}
if ( !data_err ) {
echo "All data was present…attempting to send email.";
if ( email($to,$subject,$body,$headers) ) {
echo "Email was successfully sent.<br />\n";
// Redirect to the thank you page.
header('./thanks.php');
} else {
echo "Email failed…need to determine why.<br />\n";
// Redirect to the error page.
//header('./contact-error.php');
echo "We were unable to process the message due to an error.";
}
} else {
echo "Data was missing.<br />\n";
// Redirect back to the error page.
// Need to build the error page dynamically.
// TODO: Build the error page.
}
} else if ( !$contactForm ) {
// Process the registration by creating an account in the database in
//+ which the submitted date will be stored. Also, generate a secure
//+ password for the user to use the first time s/he logs on. Then,
//+ send the user an email, detailing all of the above and then send
//+ them to a "thank you for registering page".
// Include our configuration information.
include('include/conf.php');
// Create a configuration object.
$conf = new PSConf();
// Create and initialize our variables.
$dbHost = $conf->get_databaseHost();
$dbUser = $conf->get_databaseUName();
$dbPwd = $conf->get_databasePWord();
$dbName = "pekinsoft";
} // End of form check.
?> Code: Select all
<?php
session_start();
$_SESSION['cur_file'] = $_SERVER['SCRIPT_FILENAME'];
?>
<html>
<head>
<title>PekinSOFT Systems :: Delevan, Illinois</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<?php include 'include/header.php'; ?>
<div id="page">
<div id="navigation">
<?php include 'include/nav.php'; ?>
</div>
<div id="content">
<div id="welcome">
<h3>Contact PekinSOFT Systems</h3>
<p>Please use the form below, selecting the appropriate or
closest subject, to contact PekinSOFT Systems.
</p>
<form name="contact" action="send.php" method="POST">
<table class="form">
<tr><td class="caption">Email Address:</td>
<td><input class="form_tfield" type="text"
name="email" /></td>
</tr>
<tr><td class="caption">Name:</td>
<td><input class="form_tfield" type="text"
name="name" value="First Last" /></td>
</tr>
<tr><td class="caption">Subject:</td>
<td><select class="form_tfield" type="select"
name="subject">
<option value="0">Select a subject…</option>
<option value="1">Website</option>
<option value="2">Services</option>
<option value="3">Contracts</option>
<option value="4">Something Else</option>
</select></td>
</tr>
<tr><td class="caption">Message:</td>
<td><textarea class="form_tfield" name="body"
rows="15" cols="40">
</textarea>
<input type="hidden" name="formName" value="contact" />
</td>
</tr>
<tr><td class="empty"></td>
<td><input type="reset" name="reset" value="Reset" /> |
<input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</div>
<div id="sidebar">
<ul id="news">
<?php include 'include/updates.php'; ?>
</ul>
</div>
<div style="clear: both; height: 1px"></div>
<div id="footer">
<?php include 'include/footer.php'; ?>
</div>
</div>
</div>
</body>
</html>