Jump to content

[Resolved] Simple alternative to Recaptcha


bondimedical

Recommended Posts

I would like to install a simple recaptcha on my Contact Us page and am using the tutorial here - http://myphpform.com/form-spam.php - The HTML is not a problem but the PHP

if (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}

is the issue. How do I change this so it displays the error message for Cubecart?

Link to comment
Share on other sites

I have managed to get it to work with the following code:

if (strtolower($_POST['captcha']) != 'mycode') {$GLOBALS['gui']->setError('The code entered was incorrect. Please try again.');
				httpredir('index.php?_a=contact');
				}

But what it does is clear the form of all the details which the customer entered, name, email etc. How can I prevent this from happening?

Link to comment
Share on other sites

The function CubeCart->_contact() is already coded to handle sending the visitor back to a fully-populated Contact Us page if any of several tests fail.

Basically, it assigns the $_POST['contact'] form elements back to a template variable, even if that variable won't be used if successful. But if an error is detected, the code falls through to displaying the form, but this time the form's elements are populated.

Are you constructing a separate Contact Us page?

Do you have CubeCart's reCaptcha enabled?

Link to comment
Share on other sites

Ok, then try this. In /classes/cubecart.class.php:

Find near line 1336:
private function _contact() { dbgClue(__METHOD__);
  // Contact Form
  $contact = $GLOBALS['config']->get('Contact_Form');
  if ($contact && $contact['status']) {
    $GLOBALS['gui']->addBreadcrumb($GLOBALS['language']->documents['document_contact'], currentPage());
    if (isset($_POST['contact'])) {

      foreach ($GLOBALS['hooks']->load('class.cubecart.contact') as $hook) include $hook;

      $GLOBALS['smarty']->assign('MESSAGE', $_POST['contact']);
      // Validation
      $error = false;

We need to move the default setting of the $error variable above the hook.
Change to:
private function _contact() { dbgClue(__METHOD__);
  // Contact Form
  $contact = $GLOBALS['config']->get('Contact_Form');
  if ($contact && $contact['status']) {
    $GLOBALS['gui']->addBreadcrumb($GLOBALS['language']->documents['document_contact'], currentPage());
    if (isset($_POST['contact'])) {
      $error = false;

      foreach ($GLOBALS['hooks']->load('class.cubecart.contact') as $hook) include $hook;

      $GLOBALS['smarty']->assign('MESSAGE', $_POST['contact']);
      // Validation

We can now use the hook, or simply add the new statement just after the hook.

if (strtolower($_POST['captcha']) != 'mycode') {
  $GLOBALS['gui']->setError('The code entered was incorrect. Please try again.');
  $error['captcha'] = true;
}

Now that $error is no longer false, the Contact Us form will be re-displayed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...