0) { //assume all the fields are filled out $bSubmit=true; if (!is_array($_REQUEST["required"])) $_REQUEST["required"] = array(); //check each field. If one is not filled out, set bSubmit to false and add the question to the array. foreach ($_REQUEST as $strQuestion=>$strValue) { if (in_array($strQuestion, $_REQUEST["required"])) { if (substr($strQuestion,0,2)=="q_" && strlen($strValue)==0) { $bSubmit=false; $aBad[]=$strQuestion; } } } if ($bSubmit) { $strID=dbEscape(microtime()); $strEmail = ""; foreach ($_REQUEST as $strQuestion=>$strValue) { $strBody=""; if (substr($strQuestion,0,2)=="q_" && strlen($strValue)>0) { //write the results to a file $strBody .= "'".$strID."','"; $strBody .= dbEscape(date("y-m-d h:m:s"))."','"; $strBody .= dbEscape($strClient)."','"; $strBody .= dbEscape($_REQUEST["formName"])."','"; $strBody .= dbEscape($strQuestion)."','"; $strBody .= dbEscape($strValue)."'\n"; writeToFile($strBody,$fileSaveDir.str_replace(" ","",$_REQUEST["formName"])); //store the results for the email $strEmail.= dbEscape($strQuestion) . " : ". dbEscape($strValue)."\n"; } } $strHeaders="From: ".$emailFrom; mail($emailTo, $emailSubject, $strEmail, $strHeaders); if (strlen($_REQUEST["sendEmail"])>0) mail($_REQUEST[$_REQUEST["sendEmail"]], "Website submission", "Dear ".$_REQUEST["q_firstName"]."\n\nThank you for your submission.", $strHeaders); header("Location: " . $_REQUEST["redirect"]); } } $contents=getFileContents('templateForm.php'); $str= ""; $contents = str_replace("%%JAVASCRIPT%%",$str,$contents); $header = getFileContents('../../includes/header_noPHP.php'); $side_col = getFileContents('../../includes/leftcol.php'); $footer = getFileContents('../../includes/footer.php'); echo $header; echo $side_col; echo $contents; echo $footer; ?>