***** BACKUP YOUR CATALOG + DATABASE FIRST!! *******

Credit for this contribution goes to the creators of the "anti robot registration" contri!
The code and the SQL queries were changed to make it work with your review writings.

Also Credit goes to bobbus aka bob dubois, who remastered the "anti robot registration" contri to work with the contact form

Me, jupiters,  remastered bobbus contri to make it work with the Tell-A-Friend form

* NOTE:

* Files which will be modified:

1. catalog/tell_a_friend.php
2. catalog/includes/database_tables.php
3. catalog/includes/filenames.php


STEP 1:
OPEN FILE: catalog/tell_a_friend.php

after:
require('includes/application_top.php');

add:
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_TELL_A_FRIEND_VALIDATION);
include_once('includes/functions/' . FILENAME_TELL_A_FRIEND_VALIDATION);


STEP 2:
SAME FILE:

after:
$from_email_address = tep_db_prepare_input($HTTP_POST_VARS['from_email_address']);
$from_name = tep_db_prepare_input($HTTP_POST_VARS['from_name']);
$message = tep_db_prepare_input($HTTP_POST_VARS['message']);

add:
// BOF ANTISPAM
$antispam = tep_db_prepare_input($HTTP_POST_VARS['antispam']);
// EOF ANTISPAM


STEP 3:
SAME FILE:

after:
if (!tep_validate_email($to_email_address)) {
     $error = true;
     $messageStack -> add('friend', ERROR_TO_ADDRESS);
}


add:

       
// BOF Antispam Tell-A-Friend
if ('1' == '1') {
$sql = "SELECT * FROM " . TABLE_ANTI_SPAMBOT_TELL_A_FRIEND . " WHERE session_id = '" . tep_session_id() . "' LIMIT 1";
if( !$result = tep_db_query($sql) ) {
$error = true;
$entry_antispam_error = true;
$text_antispam = ERROR_VALIDATION_1;
} else {
$entry_antispam_error = false;
$anti_spam_row = tep_db_fetch_array($result);
if (( strtolower($HTTP_POST_VARS['antispam']) != $anti_spam_row['reg_key'] ) or ($anti_spam_row['reg_key'] == '')) {
$error = true;
$entry_antispam_error = true;
$text_antispam_error = ERROR_VALIDATION_2;
} else {
$sql = "DELETE FROM " . TABLE_ANTI_SPAMBOT_TELL_A_FRIEND . " WHERE session_id = '" . tep_session_id() . "'";
if( !$result = tep_db_query($sql) )
{
$error = true;
$entry_antispam_error = true;
$text_antispam_error = ERROR_VALIDATION_3;
} else {
$sql = "OPTIMIZE TABLE " . TABLE_ANTI_SPAMBOT_TELL_A_FRIEND . "";
if( !$result = tep_db_query($sql) )
{
$error = true;
$entry_antispam_error = true;
$text_antispam_error = ERROR_VALIDATION_4;
} else {
$entry_antispam_error = false;
}
}
}

}

if (strlen($antispam) <> ENTRY_TELL_A_FRIEND_VALIDATION_LENGTH) {
$error = true;
$entry_antispam_error = true;

} else {
$entry_antispam_error = false;
}
}
// EOF Antispam Tell-A-Friend

STEP 4:
SAME FILE

after:

<tr>
            <td class="main"><b><?php echo FORM_TITLE_FRIEND_MESSAGE; ?></b></td>
          </tr>
          <tr>
            <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
              <tr class="infoBoxContents">
                <td><?php echo tep_draw_textarea_field('message', 'soft', 40, 8); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>

add:
    
<!-- BOF Anti Spambot
Tell-A-Friend -->
<tr>
<td class="main"><b><?php echo CATEGORY_ANTISPAM; ?></b></td>
</tr>
<tr>
<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
<tr class="infoBoxContents">
<td><table align="center" border="0" cellspacing="2" cellpadding="2">
<tr>
<?php
$sql = "DELETE FROM " . TABLE_ANTI_SPAMBOT_TELL_A_FRIEND . " WHERE timestamp < '" . (time() - 3600) . "' OR session_id ='" . tep_session_id() . "'";
if( !$result = tep_db_query($sql) ) { die('Could not delete validation key'); }
$reg_key = gen_reg_key();
$sql = "INSERT INTO ". TABLE_ANTI_SPAMBOT_TELL_A_FRIEND . " VALUES ('" . tep_session_id() . "', '" . $reg_key . "', '" . time() . "')";
if( !$result = tep_db_query($sql) ) { die('Could not check registration information'); }
?>
<tr>
<td class="main"><table align="center" border="0" width="100%" cellspacing="0" cellpadding="2" class="formArea">
<tr>
<td class="main"><table border="0" cellspacing="0" cellpadding="2">
<tr>
<td class="main" width="50%" NOWRAP><span class="main">&nbsp;<?php echo ENTRY_ANTISPAM; ?></span></td>
<td class="main" width="50%" align="left">
<?php
if ($entry_antispam_error == true) {
?>
<span>
<?php
$validation_images = '';
for($i = 0; $i < ENTRY_TELL_A_FRIEND_VALIDATION_LENGTH; $i++)
{
$validation_images .= tep_image(DIR_WS_IMAGES . 'validation/validation_' . $reg_key{$i} . '.gif') . '';
}
echo $validation_images . ' <br>&nbsp;';
echo tep_draw_input_field('antispam') . '&nbsp;<br><b><font color="red">' . ERROR_VALIDATION . '<br>' .
$text_antispam_error . '</b></font>';
} else {
?>

<span>
<?php
$validation_images = '';
for($i = 0; $i < ENTRY_TELL_A_FRIEND_VALIDATION_LENGTH; $i++)
{
$validation_images .= tep_image(DIR_WS_IMAGES . 'validation/validation_' . $reg_key{$i} . '.gif') . '';
}
echo $validation_images . ' <br>&nbsp;';
?>
<?php echo tep_draw_input_field('antispam', $account['entry_antispam']) . '&nbsp;' . ENTRY_ANTISPAM_TEXT; ?>
</span>
<?php
}
?>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>

<!--// EOF ANTISPAM Tell-A-Friend -->      

STEP 5:
insert the included SQL file into your MySQL database, creating a table "anti_spambot_tell_a_friend"

STEP 6:
upload the catalog/images/validation/*.gif to your site

STEP 7:
OPEN catalog/includes/database_tables.php

before:
?>

add:
define('TABLE_ANTI_SPAMBOT_TELL_A_FRIEND', 'anti_spambot_tell_a_friend');


STEP 8:
OPEN catalog/includes/filenames.php

before:
?>

add:
define('FILENAME_TELL_A_FRIEND_VALIDATION', 'tell_a_friend_validation.php');


STEP 9:
upload catalog/includes/languages/english/tell_a_friend_validation.php

upload catalog/includes/languages/german/tell_a_friend_validation.php

upload catalog/includes/languages/dutch/tell_a_friend_validation.php

upload catalog/includes/languages/espanol/tell_a_friend_validation.php

Of course Step 9 depends on what languages your shop supports



STEP 10:
upload catalog/includes/functions/tell_a_friend_validation.php to your site

That's pretty much it! Check out the admin/configuration settings for "Anti Spambot Tell-A-Friend" and you'll see you can change the number of pictures to be displayed for the validation code.