Jump to content

[SOLVED] HEADER ERRORS - I READ THE POST! I still do not understand.


Recommended Posts

I have this code. It worked fine and all of sudden stopped. No idea why. I looked for whitespace. There is none. It point to my style tag <style type="text/css" media="screen"> in the error message. How would a style tag stop it from working? I tried the ob_start and it skipped my validation screen. Not good. I am new at this and don't understand what you mean by $output or $result variable that is 1 if successful, 0 if failed.

 

I don't mind using the ob_start if someone could show me how without bypassing my validation screen. Thanks! Connie

 

<?php
include("global.inc.php");
$errors = false;
$error = array();
$error[] = 'The following errors occured while processing your form input.<ul class="list1">';
$Storing=(strlen(trim(stripslashes($_POST['project']))) > 0)?preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $_POST['project']) : '';
// Start Validation Process Here
foreach ($_POST as $fld => $val) {
   $val = trim(stripslashes($val));
   switch ($fld) {
      case 'phone':
         if(strlen($val) < 10 ){    // checking the length of the phone number. it must be more than or equal to 10 characters in length
            $error[]="<li>Please enter your phone number, including area code.</li>";
            $errors = true;   //setting the error to 1
         }
         break;
      case 'phone2':
         if(strlen($val) > 0) {
            if(strlen(trim(stripslashes($_POST['phone2']))) < 10 ){    // checking the length of the phone number. it must be more than or equal to 10 characters in length
               $error[]="<li>Please enter your entire secondary phone number, including area code. Thank you.</li>";
               $errors = true;   //setting the error to 1
            }
            else
               $errors = false;
         }
         break;
      case 'name':
     if (strlen($val) == 0) {
            $error[] ="<li>Please enter you full name.</li>";
            $errors = true;
         }
         break;
      case 'city':
     if (strlen($val) == 0) {
            $error[] ="<li>Please enter your city.</li>";
            $errors = true;
         }
         break;
      case 'state':
         if (strlen($val) == 0) {
            $error[] ="<li>Please enter your state.</li>";
            $errors = true;
         }
         break;
      case 'zip':
         if (strlen($val) == 0) {
            $error[] ="<li>Please enter your zip code.</li>";
            $errors = true;
         }
         break;

      case 'email':
         if(strlen($val) == 0) {
                $error[] ="<li>Please enter your email address.</li>";
            	$errors = true;
            }
            else {
       		if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$val)){
          		$error[] = "<li>Please enter a valid email address. Thank you.</li>";
           		$errors = true;
			}
         }
   }
}
?>
<!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" />
<title>Choose A Painter :: Your Almost done.</title>
<link href="default.css" rel="stylesheet" type="text/css" />
<style type="text/css" media="screen">
<!--
@import url("layout.css");
@import url("fieldset-alternating.css");
-->
</style>
<!--[if lte IE 7]>
    <style type="text/css" media="all">
    	@import "fieldset-alternating-ie.css";
    </style>
    <![endif]-->
<script type="text/javascript">
<!--
window.onload = function() {
hide('exterior');
hide('interior');
}

function response() {
if(document.getElementById('category').value=='exterior') {
	show('exterior');
	hide('interior');
	} 
else { if(document.getElementById('category').value=='interior') {
	hide('exterior');
	show('interior');
	}
	else { 
	hide('exterior');
	hide('interior');
	}
}
}

function show(id) {
document.getElementById(id).style.display='block';
}

function hide(id) {
document.getElementById(id).style.display='none';
}
//-->
</script>
</head>
<body>
<div id="tophead">
  <p>The power to locate the ideal partner for your next painting project.</p>
</div>
<!-- end #menu -->
<div id="header">
  <div id="logo">
    <h1>Business Name</h1>
    <div class="fivestar" align="center"><img src="images/text_5star.gif" alt="5-star" /> </div>
  </div>
  <!-- end #logo -->
  <div id="taglines">
    <div align="center">
      <p> <br />
        877.893.5477</p>
      <span>Get a Free Painting Quote<br />
      Receive a call within 24 hours</span> </div>
  </div>
  <!-- end #search -->
</div>
<!-- end #header -->
<div id="page">
  <div id="sidebar">
    <div id="login" class="boxA">
      <h2><span>Your</span> Close!</h2>
      <p>We noticed a few errors on your form. Please read to the right to find out what you need to fix.</p>
      <img src="images/exterior02.jpg" alt="" width="140" height="141" class="border" /> </div>
    <!-- end #boxA -->
  </div>
  <!-- end #sidebar -->
  <div id="content">
    <h1>WAIT! <span>We have discovered errors.</span></h1>
    <p> We appreciate that you took the time to fill out our form. However, there are a few items we need in order to direct your request to the proper location. Please look over the errors below and return to the form using the "retry" button. Thank you. </p>
    </p>
    <div class="hr1">
      <hr />
    </div>
<?php
if($errors) {
   $error[] ="</ul><input type='button' value='Retry' onClick='history.go(-1)'><br><br>";
   echo implode("\n",$error);
   }
else{
   $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));   
   $message = array();
   $message2 = array();
   $message[] = "CUSTOMER CONTACT INFORMATION:" . "\n";
   $message2[] = "CUSTOMER CONTACT INFORMATION:" . "\n";
   foreach ($_POST as $fld => $val) {
      $val = trim(stripslashes($val));
      switch ($fld) {
         case 'name':
            $message[] = 'Name: ' . $val . "\n";
            $message2[] = 'Name: ' . $val . "\n";
            break;
     	case 'phone':
            $message[] = 'Phone: ' . $val;
            $message2[] = 'Phone: ' . $val;
            break;
	case 'phone1type':
	  if(!empty($val)){
            $message[] = ' ' . $val . "\n";
            $message2[] = ' ' . $val . "\n";
		}
	 if(empty($val)){
            $message[] =  "\n";
            $message2[] = "\n";
		}
            break;
	case 'phone1time':
	  if(!empty($val)){
            $message[] = 'Call in: ' . $val . "\n";
            $message2[] = 'Call in: ' . $val . "\n";
		}
            break;     	
	case 'phone2':
	  if(!empty($val)){
            $message[] = 'Secondary Phone: ' . $val;
            $message2[] = 'Secondary Phone: ' . $val;
		}
            break;
	case 'phone2type':
	  if(!empty($val)){
            $message[] = ' ' . $val . "\n";
            $message2[] = ' ' . $val . "\n";
		}
	 if(empty($val)){
            $message[] =  "\n";
            $message2[] = "\n";
		}
            break;
	case 'phone2time':
	  if(!empty($val)){
            $message[] = 'Call in: ' . $val . "\n";
            $message2[] = 'Call in: ' . $val . "\n";
		}
            break;
	case 'email':
		$message[] = "Email:" . $val . "\n";
		$message2[] = "Email:" . $val . "\n";
            break;
	case 'address':
	  if(!empty($val)){
		$message[] = "\n" . "Address:" . "\n" . $val . "\n";
		}
            break;
	case 'address2':
	  if(!empty($val)){
            $message[] = $val . "\n";
		}
            break;
	case 'city':
            $message[] = $val . ', ';
            $message2[] = $val . ', ';
            break;
	case 'state':
            $message[] = $val . ' ';
            $message2[] = $val . ' ';
            break;
	case 'zip':
            $message[] = $val . "\n";
            $message2[] = $val . "\n";
            break;
	case 'project':
	  if(!empty($val)){
	    $message[] = "\n" . 'Project Description:' . "\n";
            $message2[] = "\n" . 'Project Description:' . "\n";
            $message[] = $val . "\n\n";
            $message2[] = $val . "\n\n";
		}
	  if(empty($val)){
            $message[] = ' ' . "\n\n";
            $message2[] = ' ' . "\n\n";
		}
            break;			
//----------PROJECT DETAILS--------------------
	case 'category':
	  if(!empty($val)){
	  	$message[] = $val . " details" . "\n" . "--------------------------" . "\n";
		$message2[] = $val . " details" . "\n" . "--------------------------" . "\n";
		}
            break;
//-------------EXTERIOR--------------------
	case 'brick':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'woodsiding':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'stucco':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'aluminum':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'trim':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'gutters':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'deck':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'lightpeeling':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'heavypeeling':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'rottenwood':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'ranch':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'colonial':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case '3story':
	  if(!empty($val)){
            $message[] = $val;
            $message2[] = $val;
		}
            break;
//-------------INTERIOR--------------------
	case 'number':
	  if(!empty($val)){
            $message[] = "Number of Rooms: " . $val . "\n";
            $message2[] = "Number of Rooms: " . $val . "\n";
		}
            break;
	case 'wholehouse':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'bedroom':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'bathroom':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'kitchen':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;	
	case 'livdinroom':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'wallpaperremoval':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'plasterrepair':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'drywallrepair':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'wallrepair':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'waterdamage':
	  if(!empty($val)){
            $message[] = $val;
            $message2[] = $val;
		}
            break;
//-------------SPECIFICS------------------		
	case 'completedate1':
	  if(!empty($val)){
            $message[] = "\n\n" . "Finish deadline: " . $val . "\n";
            $message2[] = "\n\n" . "Finish deadline: " . $val . "\n";
		}
            break;	
	case 'completedate':
	  if(!empty($val)){
            $message[] =  "\n\n" . "Finish deadline: " . $val . "\n";
            $message2[] =  "\n\n" . "Finish deadline: " . $val . "\n";
		}
            break;
	case 'squarefeet1':
	  if(!empty($val)){
            $message[] = "Square Feet: " . $val . "\n";
            $message2[] = "Square Feet: " . $val . "\n";
		}
            break;
	case 'squarefeet':
	  if(!empty($val)){
            $message[] = "Square Feet: " . $val . "\n";
            $message2[] = "Square Feet: " . $val . "\n";
		}
            break;
	case 'selling':
	  if(!empty($val)){
            $message[] = "\n" . "Reason for Painting" . "\n" . "--------------------------------" . "\n" . $val . ", ";
            $message2[] = "\n" . "Reason for Painting" . "\n" . "--------------------------------" . "\n" . $val . ", ";
		}
	  if(empty($val)){
            $message[] =  "\n" . "Reason for Painting" . "\n" . "--------------------------------" . "\n";
            $message2[] =  "\n" . "Reason for Painting" . "\n" . "--------------------------------" . "\n";
		}
            break;
	case 'purchased':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'existinghome':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'rental':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'commercial':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;			
	case 'apartment':
	  if(!empty($val)){
            $message[] = $val . ", ";
            $message2[] = $val . ", ";
		}
            break;
	case 'condo':
	  if(!empty($val)){
            $message[] = $val;
            $message2[] = $val;
		}
            break;				
      }
   }
   mail("[email protected]","Choose a Painter Quote Request",implode("",$message),"From: ".$_POST['email']);
   // mail("[email protected]","Choose a Painter Quote Request",implode("",$message),"From: ".$_POST['email']);
   mail("[email protected]","Contact Info w Address",implode("",$message2),"From: ".$_POST['email']);
header("Refresh:0;url=thankyou.html");
}
?>
<p><img src="images/interior07.jpg" alt="exterior01" width="140" height="93" class="border" /><img src="images/spacer.gif" width="30" height="1"/><img src="images/exterior05.jpg" alt="interior01" width="140" height="93" class="border" /><img src="images/spacer.gif" width="30" height="1"/> <img src="images/interior10.jpg" alt="interior01" width="140" height="93" class="border" /> 
  </div>
  </p>
  <!-- end #content -->
  <div style="clear: both;"> </div>
</div>
<!-- end #page -->
<div id="footer">
  <p>TOLL FREE: 877.893.5477</p>
  <p>Copyright (c) 2008 Chooseapainter.com All Rights Reserved.</p>
</div>
</body>
</html>

The reason is that you are calling the header() function after anything has been outputted. A quick fix would be to put ob_start() on the top and ob_end_flush() on the bottom, but that's not a good solution. It's a design flaw in your application and you should rather rewrite it to now output anything before you're done.'

 

Also (and this is unrelated to your specific problem), I'm quite sure you can work out a better solution than those huge switches you have :)

Hint: You're doing practically the same with all the things, how about using a loop?

Warning: Cannot modify header information - headers already sent by (output started at /home/vadtest7/public_html/contactchooseapainter2.php:72) in /home/vadtest7/public_html/contactchooseapainter2.php on line 480

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.