Stupid little error checking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

In your code you need to move $missing = array(); out of the if($submit){ .. } code block, so i'd just move it under the $error=0; line
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This is my code now:

Code: Select all

<?php
<? 
   include "inc/design1.php"; ?>

<?
$error=0;
$missing = array();

if ($submit){

# # # # # # # # # # ERROR CHECKING # # # # # # # # # #  
					   


 
if(!empty($_POST)){ 
  $required =      array('type','budget','time_start','time_frame','description','firstname','lastname','organization','city',
					   'state','country','email');
  foreach($required as $req){ 
    if(empty($_POST[$req])){ 
      $missing[] = $req; 
     $error=1;
	} 
  } 
} 

# # # # # # # # # # # # # # # # # # # # # # # # # # # # 



if ($error==0){

$formvariables = array($type,$type_other,$logodesign,$bannerdesign,$graphicdesign,$shoppingcart,
					   $interactivefeatures,$flashanimationandpresentation,$webhosting,$domainnameregistration,$sitemaintenance,
					   $editingandwritting,$merchantaccount,$customscripts,$creditcardprocessing,$searchengineoptimization,
					   $searchcapabilitiesonthewebsite,$databaseprogramming,$budget,$time_start,$time_frame,$description,
					   $firstname,$lastname,$organization,$address,$city,$state,$country,$phone,$fax,$email,$icq,
					   $contact_email,$contact_phone,$contact_icq,$tog);
					   
$feature =       array($logodesign,$bannerdesign,$graphicdesign,$shoppingcart,
					   $interactivefeatures,$flashanimationandpresentation,$webhosting,$domainnameregistration,$sitemaintenance,
					   $editingandwritting,$merchantaccount,$customscripts,$creditcardprocessing,$searchengineoptimization,
					   $searchcapabilitiesonthewebsite,$databaseprogramming);



# # # # # # # # # # # # # # # # # # # # # # # # # # # # 
########################################################
# # # # # # # # # # MAKING THE EMAIL # # # # # # # # # # 

$message = '<b><font size=3><u>Information about your project</u></font></b><br><br>';
$message .= '<b>Type of site: </b>'.$type.'<br>';		   
if ($type_other != ""){ 
$message .= '<b>Other: </b>'.$type_other.'<br>'; 
} 
$message .= '<b>Features for the site: </b><br>';
foreach($feature as $feat){
if(isset($feat)){
$message .= '- '.$feat.'<br>';
}
}
if (isset($features_other1)){
$message .= $features_other1.'<br>';
}
$message .= '<b>Estimated Budget:</b> '.$budget.'<br>';
$message .= '<b>Time until we can start project: </b>'.$time_start.'<br>';
$message .= '<b>Time Frame: </b>'.$time_frame.'<br>';
$message .= '<b>Overview: </b>'.$description.'<br>'; 

echo "<br>";

echo "<table border="1" width="452" border="1" cellpadding="0" cellspacing="0" bordercolor="9A9A9A" align="center">\n".
     		"<tr class="porttext" bordercolor="EFEFEF" bgcolor="EFEFEF"><td width="5%">&nbsp;<td width="90%">\n";	 
echo "<br>".$message."<br>";
echo "<td width="5%">&nbsp;</td></td></td></tr></table>\n";

# # # # # # # # # # # # # # # # # # # # # # # # # # # # 
}
}else{

?>

<FORM action=order.php method=post>
  
  <div align="center"><br>
    
	<table class="porttext" width="95%" border="0">
      <tr>
        <td>Please fill out the following form that will give us a good idea about 
          your project. We will get back to you within 24 hours with an estimate 
          or additional questions about your site. Thank you! </td>
      </tr>
    </table>
    
	<br></div>
  
  <TABLE class="porttext" cellSpacing=1 cellPadding=2 width=95% align=center bgColor=#9A9A9A border=0>
    <TBODY>
      <TR bgcolor="#CCCCCC" > 
        <TD height="23" colSpan=2 bgcolor="#CCCCCC"><B>Information about your project:</B></TD>
      </TR>
      <TR> 
        <TD colSpan=2 bgcolor="#ffffff"> <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
            
		  <TBODY class="porttext">
              <TR> 
                <TD <? if(in_array('type', $missing)){ echo ' class="error"'; }  ?> height="19" colSpan=2><B>Are you looking for: <font color="#FF0000">* </font></B> </TD>	  
			  </TR>
              <TR> 
                <TD width="6%"><INPUT type=radio value="New Web site design" name=type></TD>
                <TD width="94%">New Web site design </TD>
              </TR>
              <TR> 
                <TD><INPUT type=radio value="Re-design of the current Web site" name=type></TD>
                <TD>Re-design of the current Web site</TD>
              </TR>
              <TR> 
                <TD><INPUT type=radio value="Other" name=type></TD>
                <TD>Other (please specify below):</TD>
              </TR>
              <TR> 
                <TD></TD>
                <TD><INPUT size=50 name=type_other><br>
                  <br>
                </TD>
              </TR>
            </TBODY>
          </TABLE>
          
		  <TABLE class="porttext" cellSpacing=0 cellPadding=0 width="100%" border=0>
            <TBODY>
              <TR> 
                <TD colSpan=2><B>Please select features and services you are interested in:</B></TD>
              </TR>
              <TR> 
                <TD><INPUT name=logodesign type=checkbox id="logodesign" value="Logo Design"></TD>
                <TD>Logo Design</TD>
              </TR>
              <TR> 
                <TD><INPUT name=bannerdesign type=checkbox id="bannerdesign" value="Banner Design"></TD>
                <TD>Banner Design</TD>
              </TR>
              <TR> 
                <TD><INPUT name=graphicdesign type=checkbox id="graphicdesign" value="Graphic Design"></TD>
                <TD>Graphic Design</TD>
              </TR>
              <TR> 
                <TD><INPUT name=shoppingcart type=checkbox id="shoppingcart" value="Shopping Cart"></TD>
                <TD>Shopping Cart</TD>
              </TR>
              <TR> 
                <TD><INPUT name=interactivefeatures type=checkbox id="interactivefeatures" value="Interactive Features"></TD>
                <TD>Interactive Features (Chat, Forum, Forms)</TD>
              </TR>
              <TR> 
                <TD><INPUT name=flashanimationandpresentation type=checkbox id="flashanimationandpresentation" value="Flash Animation & Presentation"></TD>
                <TD>Flash Animation & Presentation</TD>
              </TR>
              <TR> 
                <TD><INPUT name=webhosting type=checkbox id="webhosting" value="Web Hosting"></TD>
                <TD>Web Hosting</TD>
              </TR>
              <TR> 
                <TD><INPUT name="domainnameregistration" type=checkbox id="domainnameregistration" value="Domain Name Registration"></TD>
                <TD>Domain Name Registration</TD>
              </TR>
              <TR> 
                <TD><INPUT name=sitemaintenance type=checkbox id="sitemaintenance" value="Site Maintenance"></TD>
                <TD>Site Maintenance</TD>
              </TR>
              <TR> 
                <TD><INPUT name=editingandwritting type=checkbox id="editingandwritting" value="Editing and Writing"></TD>
                <TD>Editing and Writing</TD>
              </TR>
              <TR> 
                <TD><INPUT name=merchantaccount type=checkbox id="merchantaccount" value="Merchant Account"></TD>
                <TD>Merchant Account</TD>
              </TR>
              <TR> 
                <TD><INPUT name=customscripts type=checkbox id="customscripts" value="Custom Scripts"></TD>
                <TD>Custom Scripts</TD>
              </TR>
              <TR> 
                <TD><INPUT name=creditcardprocessing type=checkbox id="creditcardprocessing" value="Credit Card Processing"></TD>
                <TD>Credit Card Processing</TD>
              </TR>
              <TR> 
                <TD><INPUT name=searchengineoptimization type=checkbox id="searchengineoptimization" value="Search Engine Optimization"></TD>
                <TD>Search Engine Optimization</TD>
              </TR>
              <TR> 
                <TD><INPUT name=searchcapabilitiesonthewebsite type=checkbox id="searchcapabilitiesonthewebsite" value="Search Capabilities on the Web Site"></TD>
                <TD>Search Capabilities on the Web Site</TD>
              </TR>
              <TR> 
                <TD><INPUT name=databaseprogramming type=checkbox id="databaseprogramming" value="Database Programming"></TD>
                <TD>Database Programming</TD>
              </TR>
              <TR> 
                <TD><INPUT type=checkbox value=Other name="Other"></TD>
                <TD>Other (please specify below):</TD>
              </TR>
              <TR> 
                <TD></TD>
                <TD><TEXTAREA name="features_other" cols=42 rows=3 id="features_other"></TEXTAREA></TD>
              </TR>
            </TBODY>
          </TABLE>
          <br>
          <table class="porttext" width="95%" border="0" cellpadding="0" cellspacing="0">
            <tr> 
              <td width="80%" height="24"><div align="left">Estimate Budget: <font color="#FF0000">*</font></div></td>
              <td width="44%"> 
			      <select name="budget">
                  <option value="Under $750" selected>Under $750 
                  <option value=$750-1,500>$750-1,500 
                  <option value=$1500-2500>$1,500-2,500 
                  <option value=$2500-4000>$2,500-4,000 
                  <option value=$4000-7000>$4,000-7,000 
                  <option value=$7000-10000$>$6,000-10,000 
                  <option value="$10,000 or higher">$10,000 or higher</option>
                  </select>
			  </td>
            </tr>
            <tr> 
              <td><div align="left">How soon do you need to start the project?: <font color="#FF0000">*</font></div></td>
              <td>
			  	  <select name="time_start">
                  <option value=A.S.A.P. selected>A.S.A.P. 
                  <option value="Within 2 weeks">Within 2 weeks 
                  <option value="Within 2-4 weeks">Within 2-4 weeks 
                  <option value="Within 4-8 weeks">Within 4-8 weeks 
                  <option value="Within 8-12 weeks">Within 8-12 weeks 
                  <option value="12+ weeks">12+ weeks</option>
                </select>
			  </td>
            </tr>
            <tr> 
              <td><div align="left">Time Frame: <font color="#FF0000">*</font>&nbsp;</div></td>
              <td>
			      <select name="time_frame">
                  <option value="Less than a week" selected>Less than a week 
                  <option value="1-2 weeks">1-2 weeks 
                  <option value="2-3 weeks">2-3 weeks 
                  <option value="3-5 weeks">3-5 weeks 
                  <option value="5-8 weeks">5-8 weeks 
                  <option value="8-12 weeks">8-12 weeks 
                  <option value="12+ weeks">12+ weeks</option>
                  </select>
			  </td>
            </tr>
          </table>
          
		  <br><br>
 
           <TABLE class="porttext" cellSpacing=0 cellPadding=0 width="100%" border=0>
            <TBODY>
              <TR> 
                <TD height="40" colspan="2">
				<B><br>Please provide a brief overview of the project:</B> <font color="#FF0000">*</font>
				</TD>
              </TR>
              <TR> 
                <TD width="6%"></TD>
                <TD width="94%"e><textarea name="description" rows=5 cols=45></textarea></TD>
              </TR>
            </TBODY>
          </TABLE>
          <br>
        </TD>
      </TR>
    </TBODY>
  </TABLE>
  <BR>
  <TABLE class="porttext" cellSpacing=1 cellPadding=2 width=95% align=center bgColor=#9A9A9A 
      border=0>
    <TBODY>
      <TR bgcolor="#CCCCCC"> 
        <TD colSpan=2><B>Your contact information</B></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD width=240>Your first name <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT size=25 name="firstname">
        </TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Last name <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT size=25 name="lastname"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Organization (Company Name) <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT size=25 name="organization"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Address </TD>
        <TD>&nbsp; <INPUT maxLength=255 size=25 name="address"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>City <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT size=25 name="city"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Area (province, state) <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT size=25 name="state"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Country <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT size=25 name="country"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Phone number including area code</TD>
        <TD>&nbsp; <INPUT maxLength=25 size=25 name="phone"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Fax number (optional)</TD>
        <TD>&nbsp; <INPUT maxLength=25 size=25 name="fax"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>Email <font color="#FF0000">*</font></TD>
        <TD>&nbsp; <INPUT maxLength=255 size=25 name="email"></TD>
      </TR>
      <TR bgColor=#ffffff> 
        <TD>ICQ</TD>
        <TD>&nbsp; <INPUT maxLength=255 size=25 name="icq"></TD>
      </TR>
      <TR align=left bgColor=#ffffff> 
        <TD>Prefered way to contact you:</TD>
        <TD> <TABLE class="porttext" cellSpacing=0 cellPadding=0 align=left border=0>
            <TBODY>
              <TR> 
                <TD><INPUT name="contact_email" type=checkbox value=YES></TD>
                <TD>E-Mail</TD>
              </TR>
              <TR> 
                <TD><INPUT type=checkbox value=YES name="contact_phone"></TD>
                <TD>Phone</TD>
              </TR>
              <TR> 
                <TD><INPUT type=checkbox value=YES name="contact_icq"></TD>
                <TD>ICQ</TD>
              </TR>
            </TBODY>
          </TABLE></TD>
      </TR>
    </TBODY>
  </TABLE>
  <br>
  <table class="porttext" width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td><div align="left"> Do you accept the <a href="legal/tog.php" class="portlink3 href="legal/tog/">terms of agrement</a>? 
            <select name=select>
            <option value="yes">yes</option>
            <option value="no">no</option>
            </select>
            <font color="#FF0000">*</font> </div></td>
    </tr>
  </table>
  <CENTER>
    <BR>
    <INPUT name="submit" type=submit value="Send request">
    <INPUT name="reset"  type=reset value="Clear form">
  </CENTER>
</FORM>

<? 
}

include "inc/design2.php";
 
 ?>
?>
When I click submit the screen is left blank.... except for the template files.. but order.php is blank. :S
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Ok, when you are using type in <? if(in_array('type', $missing)){ echo ' class="error"'; } ?> i think you think that 'type' refers to the 'type' in <input type= .. it doesn't and can't.

As you're not flagging exactly which fields are missing (my code was designed to do that, but it doesn't matter anyway) , you can just do this instead.
<? if(!empty($missing)){ echo ' class="error"'; } ?>


Also, as i said above, unless you have register_globals On, you'll need to do if(!empty($_POST['submit'])){ instead of if($submit){
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

type refers to the value not the actual type
not sure if thats what u just said or whatnot... but this is really starting to bother me.. .WORK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LOL
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Aplogies, didn't see the name=type stuff in the first part of the form. In that case <? if(in_array('type', $missing)){ echo ' class="error"'; } ?> should work ok.

I think i'm just confusing you more as i'm getting tired ... time for me to take a break methinks ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

muchoz thanks for ur help..i guess im on my own........ page is still coming up blank :S
Post Reply