Copyright: 2007 Eugene Orlov
Version: 1.0 October 2007
Make sure the path to the library is correct.
*/
include("captcha.function.php5");
session_start();
$article = $_POST["article"];
$origin = $_POST["origin"];
$initial = $_POST["initial"];
// Change this to your real email address:
$myemail = 'briankimerer@yahoo.com';
// Initialising the $error variable. At the start it is 0. Each field in this form is processed, and if something is wrong (empty input, wrong email address, invalid captcha code, etc) $error is incremented. Form will stop processing if $error is > 0.
$error = 0;
$name_text = 'Please enter your name';
$name = '';
$email_text = 'Enter an email address if you would like to.';
$email = '';
$message_text = 'Please enter your message';
$message = '';
$captcha_text = "
I hate to inconvenience you, but the following is necessary to avoid spambots leaving scat.
";
$captcha_text = $captcha_text . "Please enter the symbols that you can see in the image below into the text area beneath the image.
";
$captcha_text = $captcha_text . "The SPAM bots are not able to read the image, but you can!
";
$captcha_text = $captcha_text . "(Hint: The letters are case sensitive.)
";
// This piece of code decides whether to show the form or to process it
// if (!isset($_POST['action']) || $_POST['action'] != 'submit') {
// if($_POST['value'] == 'Add Comment') {
if($initial == "true") {
// if ( ( strlen( $name ) == 0 ) || ( strlen( $message ) == 0 ) ){
show_form();
die;
}
// Ok, let's process the form
else {
// Checking name
if (empty($_POST['name'])) {
$error .= 1;
$name_text = 'How am I going to know what to call you? Please enter your name.';
} else {
$error .= 0;
$name_text = 'Your name is:';
// Please note, that in 'real life' you have to do something like this with user's data:
// mysql_real_escape_string(strip_tags(trim($_POST['name'])));
$name = strip_tags($_POST['name']);
}
// Checking email
if (empty($_POST['email'])) {
$error .= 0;
// $email_text = 'Please enter your email';
} elseif (!eregi('^[-!#$%&\'*+\\./0-9=?A-Z^_a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_a-z{|}~]+$', $_POST['email'])) {
$error .= 1;
$email_text = 'The email address doesn\'t look right. Please enter correct email address or leave it blank. Thanks.';
$email = strip_tags($_POST['email']);
} else {
$error .= 0;
$email_text = 'Your email address is:';
$email = strip_tags($_POST['email']);
}
// Checking message
if (empty($_POST['message'])) {
$error .= 1;
$message_text = 'Ya gotta leave some kind of message! Please enter your message';
} elseif ((strlen($_POST['message']) < 5)) {
$error .= 1;
$message_text = 'What kind if comment is that? Please enter no fewer than 5 symbols. ';
$message = $_POST['message'];
} else {
$error .= 0;
$message_text = 'Your message is:';
$message = $_POST['message'];
}
// Now let's check The CAPTCHA
if (!captcha_verify_word()) {
$error .= 1;
$captcha_text = 'Sorry. Wrong image code. Some of the images are hard to read. Please try again.
';
$captcha_text = $captcha_text . "(Hint: The letters are case sensitive.)";
} else {
$error .= 0;
}
// If $error is > 0, we'll show the form again
if ($error > 0) {
show_form();
die;
} else {
// If everything is ok, we'll post the comment and send an email
$now=date('l dS F Y h:i:s A');
$filename=$article . ".txt";
$returnurl = $origin;
@chmod( $filename, 0755 );
$handle=fopen( $filename, 'a' );
$name = strip_tags( $name );
$message = strip_tags( $message, '
' );
fwrite ($handle, "\n
The only HTML tags allowed in the comment are the <p> (new paragraph) tag and the <br> (new line) tag.
All of the fields are required except for your email address.
You can leave an email address if you would like, but it is not required.
I will not give your email address to anyone!
I hate SPAM, which is why I request that you enter letters from the CAPTCHA image below.
\n" ); fwrite ($handle, "$message