9 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
13 <style type=
"text/css">
15 .error { color: #f00; font-weight: bold; font-size: 1.2em; }
16 .success { color: #00f; font-weight; bold; font-size: 1.2em; }
17 fieldset { width: 90%; }
18 legend { font-size: 24px; }
19 .note { font-size: 18px;
26 <legend>Example Form</legend>
29 This is an example
PHP form that processes user information, checks
for errors, and validates the captcha code.<br />
30 This example form also demonstrates how to submit a form to itself to display error messages.
36 $GLOBALS[
'ct_msg_subject'] =
'Securimage Test Contact Form';
41 <span
class=
"error">There was a problem with your submission. Errors are displayed below in red.</span><br /><br />
42 <?php elseif (isset(
$_SESSION[
'ctform'][
'success']) &&
$_SESSION[
'ctform'][
'success'] ==
true): ?>
43 <span class=
"success">The captcha was correct and the message has been sent!</span><br /><br />
46 <form method=
"post" action=
"<?php echo $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING'] ?>" id=
"contact_form">
47 <input type=
"hidden" name=
"do" value=
"contact" />
50 <strong>Name*:</strong> <?php echo @
$_SESSION[
'ctform'][
'name_error'] ?><br />
51 <input type=
"text" name=
"ct_name" size=
"35" value=
"<?php echo htmlspecialchars(@$_SESSION['ctform']['ct_name']) ?>" />
55 <strong>Email*:</strong> <?php echo @
$_SESSION[
'ctform'][
'email_error'] ?><br />
56 <input type=
"text" name=
"ct_email" size=
"35" value=
"<?php echo htmlspecialchars(@$_SESSION['ctform']['ct_email']) ?>" />
60 <strong>URL:</strong> <?php echo @
$_SESSION[
'ctform'][
'URL_error'] ?><br />
61 <input type=
"text" name=
"ct_URL" size=
"35" value=
"<?php echo htmlspecialchars(@$_SESSION['ctform']['ct_URL']) ?>" />
65 <strong>Message*:</strong> <?php echo @
$_SESSION[
'ctform'][
'message_error'] ?><br />
66 <textarea name=
"ct_message" style=
"width: 450px; height: 200px"><?php echo htmlspecialchars(@
$_SESSION[
'ctform'][
'ct_message']) ?></textarea>
70 <img
id=
"siimage" style=
"border: 1px solid #000; margin-right: 15px" src=
"./securimage_show.php?sid=<?php echo md5(uniqid()) ?>" alt=
"CAPTCHA Image" align=
"left">
71 <
object type=
"application/x-shockwave-flash" data=
"./securimage_play.swf?audio_file=./securimage_play.php&bgColor1=#fff&bgColor2=#fff&iconColor=#777&borderWidth=1&borderColor=#000" height=
"32" width=
"32">
72 <param name=
"movie" value=
"./securimage_play.swf?audio_file=./securimage_play.php&bgColor1=#fff&bgColor2=#fff&iconColor=#777&borderWidth=1&borderColor=#000">
75 <a tabindex=
"-1" style=
"border-style: none;" href=
"#" title=
"Refresh Image" onclick=
"document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false"><img src=
"./images/refresh.png" alt=
"Reload Image" onclick=
"this.blur()" align=
"bottom" border=
"0"></a><br />
76 <strong>Enter Code*:</strong><br />
77 <?php echo @
$_SESSION[
'ctform'][
'captcha_error'] ?>
78 <input type=
"text" name=
"ct_captcha" size=
"12" maxlength=
"8" />
83 <input type=
"submit" value=
"Submit Message">
99 if ($_SERVER[
'REQUEST_METHOD'] ==
'POST' && @
$_POST[
'do'] ==
'contact') {
102 foreach(
$_POST as $key => $value) {
103 if (!is_array($key)) {
105 if ($key !=
'ct_message') $value = strip_tags($value);
106 $_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
110 $name = @
$_POST[
'ct_name'];
111 $email = @
$_POST[
'ct_email'];
113 $message = @
$_POST[
'ct_message'];
114 $captcha = @
$_POST[
'ct_captcha'];
115 $name = substr($name, 0, 64);
122 if (strlen($name) < 3) {
124 $errors[
'name_error'] =
'Your name is required';
127 if (strlen($email) == 0) {
129 $errors[
'email_error'] =
'Email address is required';
130 }
else if ( !preg_match(
'/^(?:[\w\d]+\.?)+@(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/i', $email)) {
132 $errors[
'email_error'] =
'Email address entered is invalid';
135 if (strlen($message) < 20) {
137 $errors[
'message_error'] =
'Please enter a message';
144 require_once dirname(__FILE__) .
'/securimage.php';
147 if ($securimage->check($captcha) ==
false) {
148 $errors[
'captcha_error'] =
'Incorrect security code entered<br />';
155 $message =
"A message was submitted from the contact form. The following information was provided.<br /><br />"
156 .
"Name: $name<br />"
157 .
"Email: $email<br />"
160 .
"<pre>$message</pre>"
161 .
"<br /><br />IP Address: {$_SERVER['REMOTE_ADDR']}<br />"
162 .
"Time: $time<br />"
163 .
"Browser: {$_SERVER['HTTP_USER_AGENT']}<br />";
165 $message = wordwrap($message, 70);
169 mail(
$GLOBALS[
'ct_recipient'],
$GLOBALS[
'ct_msg_subject'], $message,
"From: {$GLOBALS['ct_recipient']}\r\nReply-To: {$email}\r\nContent-type: text/html; charset=ISO-8859-1\r\nMIME-Version: 1.0");
177 $_SESSION[
'ctform'][
'ct_email'] = $email;
179 $_SESSION[
'ctform'][
'ct_message'] = $message;
181 foreach(
$errors as $key => $error) {
183 $_SESSION[
'ctform'][$key] =
"<span style=\"font-weight: bold; color: #f00\">$error</span>";