Contact Form

 

\n"; $html .= "\n"; $html .= "\n"; $GLOBALS['cfCharCountFunc'] = 1; return $html; } } function getXmlFile($file, $utf8 = true){ function deutf8(&$val){ $val = utf8_decode($val); } // new dom element $dom = new DomDocument(); $dom->load($file); // get the 'item' elements if ($domItems = $dom->getElementsByTagName("item")){ $i = 0; $fields = array(); foreach($domItems as $di){ $fields[$i][0] = ($di->getAttribute("caption")); $fields[$i][1] = ($di->getAttribute("name")); $fields[$i][2] = ($di->getAttribute("type")); $fields[$i][3] = ($di->getAttribute("attr")); $fields[$i][4] = ($di->getAttribute("mandatory")); $fields[$i][5] = ($di->getAttribute("error")); if ($utf8 !== true){ array_walk($fields[$i], "deutf8"); } $i++; } return $fields; }else return false; } /* ---------------------------------------------------------------------------------- | script start | ---------------------------------------------------------------------------------- */ // load config include_once("config.inc.php"); // load mailer class require_once("lib/mailer/class.phpmailer.php"); // captcha stuff $_SESSION['fp_captcha_case'] = $fpCfg['captcha_case']; $_SESSION['fp_captcha_symbol'] = $fpCfg['captcha_symbol']; $_SESSION['fp_captcha_shapes'] = $fpCfg['captcha_shapes']; $_SESSION['fp_captcha_width'] = $fpCfg['captcha_width']; $_SESSION['fp_captcha_height'] = $fpCfg['captcha_height']; $_SESSION['fp_captcha_min_chars'] = $fpCfg['captcha_min_chars']; $_SESSION['fp_captcha_max_chars'] = $fpCfg['captcha_max_chars']; // set version number & stuff $version = "1.0"; $errorPointer = ($fpCfg['posError'] == "above") ? "↓ " : "↑ "; $fields = getXmlFile($_SERVER['DOCUMENT_ROOT'].$fpCfg['dirScript']."form.xml", $fpCfg['utf8_encoding']); // get message caption/values indent $fpCfg['msgIndent'] = 0; foreach ($fields as $field){ if ($field[2] != "captcha"){ if (strlen($field[0]) > $fpCfg['msgIndent'] && $field[2] != "divider") $fpCfg['msgIndent'] = strlen($field[0]); } } $fpCfg['msgIndent'] += 3; // start form evaluation unset($error); if ($_REQUEST['do']=="send"){ $error = false; $fromAddress = ""; $message = ""; foreach ($fields as $field){ if ($field[4] == "*"){ if ($field[3] == "email"){ if (!isValidEmail($_REQUEST[$field[1]])) $error[$field[1]] = $field[5]; }else{ if ($field[2] == "file"){ if ($_FILES[$field[1]]['size'] < 1) $error[$field[1]] = $field[5]; }else if ($field[2] == "captcha"){ $hash = ($fpCfg['captcha_case'] === true) ? strtolower($_REQUEST[$field[1]]) : $_REQUEST[$field[1]]; if (md5($hash) != $_SESSION["fp_captchahash_".$field[1]]) $error[$field[1]] = $field[5]; }else{ if ($_REQUEST[$field[1]] == "" || $_REQUEST[$field[1]] == " " || $_REQUEST[$field[1]] == " ") $error[$field[1]] = $field[5]; } } } } if ($error === false){ // init mail class $mail = new PHPMailer(); $mail->Subject = $fpCfg['emailSubject']; $mail->IsMail(); $mail->FromName = ""; $mail->AddAddress($fpCfg['targetAddress']); $message = $fpCfg['emailSubject']." \n"; for ($i = 0; $i < strlen($fpCfg['emailSubject']); $i++) $message .= "*"; $message .= " \n\n".$fpCfg['msgDate'].":".spaces($fpCfg['msgIndent']-strlen($fpCfg['msgDate'])).date($fpCfg['dateFormat']); foreach ($fields as $field){ if ($field[2] == "divider"){ $message .= "\n---------------------------------------"; }else if ($field[2] == "file"){ if (is_uploaded_file($_FILES[$field[1]]['tmp_name'])){ $name = preg_replace("/[^a-zA-Z0-9\-\_\.]/", "_", $_FILES[$field[1]]['name']); $mail->AddAttachment($_FILES[$field[1]]['tmp_name'], $name, "base64", $_FILES[$field[1]]['type']); $message .= "\n".$field[0].":".spaces($fpCfg['msgIndent']-strlen($field[0])); $message .= $name; } }else if ($field[2] != "captcha"){ $message .= "\n".$field[0].":".spaces($fpCfg['msgIndent']-strlen($field[0])); // kill ' if magic quotes on if (get_magic_quotes_gpc() == 1){ if (is_array($_REQUEST[$field[1]])){ $tmp = array(); foreach ($_REQUEST[$field[1]] as $key => $val){ $tmp[$key] = stripslashes($val); } $_REQUEST[$field[1]] = $tmp; }else{ $_REQUEST[$field[1]] = stripslashes($_REQUEST[$field[1]]); } } if ($field[3] == "email"){ $message .= "mailto:".$_REQUEST[$field[1]]; $mail->From = $_REQUEST[$field[1]]; }else if ($field[2] == "checkbox" || $field[2] == "multiselect"){ $multi = ""; foreach ($_REQUEST[$field[1]] as $val){ $divider = ($multi != "") ? ", " : ""; $multi .= (isset($val) && $val != "") ? $divider.$val : ""; } $message .= $multi; }else{ $message .= $_REQUEST[$field[1]]; } } $message .= " "; } $message .= "\n  "; // set mail message $mail->Body = $message; // send mail if ($mail->Send() !== true){ echo $mail->ErrorInfo; } echo $fpCfg['txtThankyou']; //echo "

Mail Message

(This demo does not send any mails - but the message would be like below)
 "; //echo "
$message
"; } } if ($error!==false){ $html = ""; // draw form $html .= "\n\n \n\n"; $html .= "
\n"; $html .= "\n"; foreach ($fields as $field){ $htmlError = ""; $htmlField = ""; if ($field[2] == "divider"){ $html .= ""; }else{ $html .= "\n\n"; } $html .= "\n"; $html .= "\n"; $html .= "
".$field[0]."
".$field[0].$field[4]." "; } switch ($field[2]){ case "line": $htmlField = ""; if (isset($error[$field[1]])) $htmlError = "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "file": $htmlField = ""; if (isset($error[$field[1]])) $htmlError = "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "field": if (is_numeric($field[3])){ $attrVal = "cfCount('cf_".$field[1]."', 'cf_remchars_".$field[1]."', ".$field[3].")"; $attr = "onkeydown=\"$attrVal\" onkeyup=\"$attrVal\""; }else $attr = ""; $htmlField .= "\n"; if (is_numeric($field[3])){ $remChars = (isset($_REQUEST[$field[1]])) ? ($field[3] - strlen($_REQUEST[$field[1]])) : $field[3]; $htmlField .= jsCharCount()."
".$fpCfg['txtRemainingChars']." ".$remChars.""; } if (isset($error[$field[1]])) $htmlError .= "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "radio": preg_match_all("/\{(.*?)\}/", $field[3], $foo); $options = $foo[1]; $i=1; foreach ($options as $opt){ $opt = explode("|", $opt); $label = $opt[0]; $value = (isset($opt[1])) ? $opt[1] : $opt[0]; $checked = ($_REQUEST[$field[1]] == $value) ? "checked" : ""; $htmlField .= "   "; $i++; } if (isset($error[$field[1]])) $htmlError .= "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "checkbox": preg_match_all("/\{(.*?)\}/", $field[3], $foo); $options = $foo[1]; $i=1; foreach ($options as $opt){ $opt = explode("|", $opt); $label = $opt[0]; $value = (isset($opt[1])) ? $opt[1] : $opt[0]; $checked = ($_REQUEST[$field[1]][($i)] == $value) ? "checked" : ""; $htmlField .= "   "; $i++; } if (isset($error[$field[1]])) $htmlError .= "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "select": preg_match_all("/\{(.*?)\}/", $field[3], $foo); $options = $foo[1]; $i=1; $htmlField .= "\n\n"; if (isset($error[$field[1]])) $htmlError .= "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "multiselect": preg_match_all("/\{(.*?)\}/", $field[3], $foo); $options = $foo[1]; $i=1; $htmlField .= "\n\n"; if (isset($error[$field[1]])) $htmlError .= "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $htmlError.$htmlField : $htmlField.$htmlError; break; case "captcha": $_SESSION['fp_captcha_hash_name'] = "fp_captchahash_".$field[1]; $captcha = "\"captcha
"; $htmlField = ""; if (isset($error[$field[1]])) $htmlError = "
".$errorPointer.$error[$field[1]]."
"; $html .= ($fpCfg['posError'] == "above") ? $captcha.$htmlError.$htmlField : $captcha.$htmlField.$htmlError; break; } $html .= "
 * ".$fpCfg['txtMandatory']."
 \n"; $html .= "
\n"; $html .= "
\n"; $html .= "\n \n\n"; echo $html; } /* ---------------------------------------------------------------------------------- | EOF FormPro Script | ---------------------------------------------------------------------------------- */ ?>