Contact Form not submitting

I’m trying to create a contact form with checkboxes or radio buttons for the first time and am having issues. I did some research, but still don’t think the code is right. Right now the validation doesn’t work and when you click submit the page just refreshes with a blank form. It doesn’t actually submit.

http://empirebathandkitchen.com/test/php/mc_contact_form_new.php is the test page

HTML:


<!-- DO NOT EDIT -->
<form action="<?php echo $PHP_SELF;?>" method="post">
<table cellpadding="5" border="0">
<tr>
<td colspan="2"> First Name:<br> <input name="firstname" type="text" size="25"></td>
<td colspan="2"> Last Name:<br> <input name="lastname" type="text" size="25"></td>
</tr>
<tr>
<td colspan="4"> Business:<br> <input name="company" type="text" size="40"></td>
</tr>
<tr>
<td colspan="4"> Address:<br> <input name="address" type="text" size="40"></td>
</tr>
<tr>
<td colspan="2"> City:<br> <input name="city" type="text"  size="20"> </td>
<td> State:<br> <input name="state" type="text" size="10"> </td>
<td> Zip:<br> <input name="zip" type="text" size="10"> </td>
</tr>
<tr>
<td colspan="2"> Phone:<br> <input name="phone" type="text" size="20"> </td>
<td colspan="2"> Email Address:<br> <input name="email" type="text" size="20"> </td>
</tr>
<tr>
<td colspan="2">What is your project time frame?<br />
	<input type="checkbox" name="timeframe[]" value="Now - 3 Months" checked="checked">Now - 3 Months<br />
	<input type="checkbox" name="timeframe[]" value="3 Months - 6 Months">3 Months - 6 Months<br />
	<input type="checkbox" name="timeframe[]" value="6 Months - 9 Months">6 Months - 9 Months<br />
	<input type="checkbox" name="timeframe[]" value="9 Months - Year>">9 Months - Year<br />
	<input type="checkbox" name="timeframe[]" value="Over A Year">Over A Year
</td>
<td colspan="2">Project Type:<input type="hidden" name="projecttype" value="0" />
<input name="projecttype[]" type="checkbox" value="New Build" checked="checked">New Build or <input type="checkbox" name="projecttype" value="Remodel">Remodel<br />

<input type="checkbox" name="project[]" value="Kitchen" checked="checked">Kitchen<br />
<input type="checkbox" name="project[]" value="Bathroom">Bathroom<br />
<input type="checkbox" name="project[]" value="Other">Other  <input name="other" type="text" size="20">
</td>
</tr>
<tr>
<td colspan="2">Do you have a contractor?
<input type="checkbox" name="contractor[]" value="Yes">Yes <input name="contractor" type="checkbox" value="No" checked="checked">No<br /><br />
If yes, please fill out: <textarea name="contractordetails" cols=40 rows=4 maxlength="400"></textarea>
</td>
</tr>
<tr>
<td colspan="4"> Additional Comments &amp; Information:<br> <textarea name="comments" cols=40 rows=4 maxlength="400"></textarea></td>
</tr>
<tr>
<td colspan="4"><img src="mc_captcha.php" class="imginline" width="90" height="30">
Re-Type Confirmation Code: <input name="code" type="text" size="20">
</td>
</td>
<tr>
<td colspan="4"> <input name="submit" id="submit" type="submit" value="Submit"> &nbsp; <input type="reset" value="Reset"> </td>
</tr>
</table>
</form>

PHP


&lt;?
session_start();
?&gt;
&lt;!-- CONTENT AREA GOES HERE --&gt;

&lt;?php
if($_SERVER["REQUEST_METHOD"] == "POST")     {
    foreach($_POST as $key =&gt; $val) {
        if(is_array($_POST[$key])) $_POST[$key] = implode(", ", $_POST[$key]);
    }
}
?&gt;
&lt;?php
if (isset($_POST['submit']))
{
//SET EMTPY ERROR
$errorset = 0;

//GET FORM DETAILS
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$company = $_POST["company"];
$realaddress = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$timeframe = $_POST["timeframe"];
$projecttype = $_POST["projecttype"];
$project = $_POST["project"];
$projectdetails = $_POST["projectdetails"];
$contractor = $_POST["contractor"];
$contractordetails = $_POST["contractordetails"];
$comments = $_POST["comments"];


//CHECK FOR ERRORS ON REQUIRED FIELDS

//Encrypt the posted code field and then compare with the stored key
if(md5($_POST['code']) != $_SESSION['captchakey'])
{
echo "Your confirmation code does not match, go back and re-type!&lt;br&gt;";

//echo md5($_POST['code']);
//echo " does not equal passed key:   ";
//echo $_SESSION['captchakey'];
//echo "&lt;br&gt;";

$errorset += 1;
}

if ($firstname == "") {
echo "Required field &lt;b&gt;First Name&lt;/b&gt; not set!&lt;br&gt;";
$errorset += 1;
}

if ($lastname == "") {
echo "Required field &lt;b&gt;Last Name&lt;/b&gt; not set!&lt;br&gt;";
$errorset += 1;
}

//EMAIL CHECK
function ValidateEmail($address)
{
    if (function_exists('filter_var')) { //Introduced in PHP 5.2
      if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
        return false;
      } else {
        return true;
      }
    } else {
      return preg_match('/^(?:[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+\\.)*[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\\-](?!\\.)){0,61}[a-zA-Z0-9_-]?\\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\\[(?:(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\]))$/', $address);
    }
}

if (($email == "") || (!ValidateEmail($email))) {
echo "Required field &lt;b&gt;E-Mail&lt;/b&gt; not set or invalid!&lt;br&gt;";
$errorset += 1;
}
// END EMAIL CHECK

if (!isset($_POST["timeframe"])) {
echo "Required field &lt;b&gt;Time Frame&lt;/b&gt; not selected!&lt;br&gt;";
$errorset += 1;	   }

if (!isset($_POST["projecttype"])) {
echo "Required field &lt;b&gt;Project Type&lt;/b&gt; not selected!&lt;br&gt;";
$errorset += 1;	}

if (!isset($_POST["project"])) {
echo "Required field &lt;b&gt;Project&lt;/b&gt; not selected!&lt;br&gt;";
$errorset += 1;	}

if (!isset($_POST["contractor"])) {
echo "Required field &lt;b&gt;Contractor&lt;/b&gt; not selected!&lt;br&gt;";
$errorset += 1;	}


// SETUP THE MESSAGE WE ARE SENDING
$fullmsg = "Email From: ".$firstname." ".$lastname."&lt;br&gt;";
$fullmsg .= "Email Address: ".$email." &lt;br&gt;";
$fullmsg .= "Company: ".$company." &lt;br&gt;";
$fullmsg .= "Address: ".$realaddress." &lt;br&gt;";
$fullmsg .= "City: ".$city." &lt;br&gt;";
$fullmsg .= "State: ".$state." &lt;br&gt;";
$fullmsg .= "Zip: ".$zip." &lt;br&gt;";
$fullmsg .= "Phone: ".$phone." &lt;br&gt;";
$fullmsg .= "Timeframe: ".$timeframe." &lt;br&gt;";
$fullmsg .= "Project Type: ".$projecttype." &lt;br&gt;";
$fullmsg .= "Project: ".$project." &lt;br&gt;";
$fullmsg .= "Details: ".$projectdetails." &lt;br&gt;";
$fullmsg .= "Contractor: ".$contractor." &lt;br&gt;";
$fullmsg .= "Contractor Details: ".$contractordetails." &lt;br&gt;";
$fullmsg .= "Message: "."&lt;br&gt;".$comments;

//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');

//GET MAILER CLASS
require_once('mc_class.phpmailer.php');

// EXTRA ERROR CHECKING ROUTINE by tREMor
if ($errorset == 0)
{
$mail             = new PHPMailer();
$body             = $fullmsg;
$body             = eregi_replace("[\\]",'',$body);
$mail-&gt;IsSMTP(); // telling the class to use SMTP
$mail-&gt;Host       = "k2smtpout.secureserver.net"; // SMTP server
$mail-&gt;SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail-&gt;SetFrom("$email", "$firstname $lastname");
$mail-&gt;AddReplyTo("$email", "$firstname $lastname");
$mail-&gt;Subject    = "Web Form Submission";
$mail-&gt;MsgHTML($body);
$address = "mikev@promediaonline.com";
$mail-&gt;AddAddress($address, "Mike");


	if(!$mail-&gt;Send())
	{
		echo "&lt;p&gt;Mailer Error: " . $mail-&gt;ErrorInfo ." &lt;/p&gt;";
	}
	else
	{
        echo "&lt;p&gt;Mail Sent:&lt;/p&gt;";

        include("mc_contact-thankyou.html");
	}
}
else
{
    echo "&lt;p&gt;Please fill in all required fields to submit your contact form.&lt;/p&gt;";
    //echo "&lt;p&gt;&lt;a href='javascript: history.go(-1)'&gt;Click Here&lt;/a&gt;&lt;/p&gt;";
    include("mc_contact_form_new.php");
}

}
else
{
    include("mc_contact_form_new.php");
    //session_write_close();
}
?&gt;

I should add the form already existed and was created years ago, but the client wants to add the new checkbox fields so I’m trying to alter the existing form.

Hi,

At first glance there’s a problem with your form action… you’ve got <?php echo $PHP_SELF;?> which should actually be <?php echo htmlentities($_SERVER[‘PHP_SELF’]); ?> (running the variable through htmlentities() prevents XSS attacks: http://www.html-form-guide.com/php-form/php-form-action-self.html).